⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fentity.m

📁 仿真人工金融市场Jackson代码
💻 M
字号:
// #define __USE_FIXED_PROTOTYPES__  // for gcc headers#import <math.h>//#include <string.h>//#include <stdio.h>//#include <stdlib.h>//#import <tkobjc.h>//#import <gui.h>//#import <simtools.h>#import <random.h>#import "FEntity.h"#import "ILink.h"#import "BLink.h"#import "BankModelSwarm.h"@implementation FEntity- setCanvas: aCanvas{  [super setCanvas: aCanvas];  if (investLink)    [investLink setCanvas: aCanvas];  if (borrowLink)    [borrowLink setCanvas: aCanvas];  return self;}- setIncome: (double) aVal andAv: (double) avInc { //***   Income = aVal ; // ***   averageIncome =  avInc ; // ***  return self ;   // ***}- setTranCostBas: (double) aVal {                 TranCostBas = aVal  ; // ***return self;   // ***}  // *** -setTotalAgentNum: (int) total {  totalAgentNum = total ;  return self ;}-makeInvestLinkTo: aFEntity {  investLink = [[[[ILink createBegin: [self getZone]]                           setCanvas: canvas]                          setFrom: self To: aFEntity]                           createEnd] ;  return self ;}-makeBorrowLinkTo: aFEntity {  borrowLink = [[[[BLink createBegin: [self getZone]]                           setCanvas: canvas]                          setFrom: self To: aFEntity]                           createEnd] ;  return self ;}-transferInvestLinkTo: aFEntity {  [investLink drop] ;  [self makeInvestLinkTo: aFEntity] ;  return self ;}-transferBorrowLinkTo: aFEntity {  [borrowLink drop] ;  [self makeBorrowLinkTo: aFEntity] ;  return self ;}-createEnd {  [super createEnd] ;  [self makeInvestLinkTo: self] ;   [self makeBorrowLinkTo: self] ;  IOPbool = 0 ;  loanCount = 0 ;  investCount = 0;  capital = 0 ;  IOPG = 0 ; // ***  ciclo= 1 ; // ***  return self ;}-(int) getPrevROI {  return prevROI ;}-(int) getPrevCapital {  return prevCapital ;}-(const char *)getInstanceName {  return label ;}-setEntityName: (char *) the_name{  label = the_name ;  return self ;}-setModel: aModelSwarm {  model = aModelSwarm ;  return self ;}-attrIncome{                           //***            [self setIncome: [uniformDblRand  getDoubleWithMin: 0.0   //***            withMax: averageIncome] andAv: averageIncome];          //***return self;}                                                           //**-attrTranCostBas{                           // ***           [self setTranCostBas: TranCostBas]; // ***return self; // ***} // ***-encounter {    id someone;  if([uniformDblRand getDoubleWithMin: 0.0                              withMax: 1.0]                       < [model getProbEncounter]){    someone = [model getRandomFEntity] ;    if([someone getPrevROI] > [[investLink getTo] getPrevROI])      [self transferInvestLinkTo: someone] ;    if([someone getPrevCapital] > [[borrowLink getTo] getPrevCapital])      [self transferBorrowLinkTo: someone] ;  }  ciclo++; // ***  return self ;}-collectInvestment: (int) amount {  investCount++ ;  capital += amount ;  return self ;}-invest{  [[investLink getTo] collectInvestment: Income] ; // ***  return self ;}-requestLoan {  loanCount++ ;  return self ;}-generateIOP{  if([uniformDblRand getDoubleWithMin: 0.0                              withMax: 1.0] < [model getProbIOP]){    if(canvas){      //set the border width once and for all somewhere else...      [[nodeItem setBorderColor: "blue"] setBorderWidth: 3] ;      GUI_UPDATE_IDLE_TASKS ();    }    [[borrowLink getTo] requestLoan] ;    IOPbool = 1 ;  }  return self ;}-(int)borrowingFrom: anFEntity {  if(([borrowLink getTo] == anFEntity) && IOPbool)    return 1 ;  else    return 0 ;}-(int)investingIn: anFEntity {  if([investLink getTo] == anFEntity)    return 1 ;  else    return 0 ;}-(double) generateROI: (double) investment {     if(canvas){    [nodeItem setBorderColor: "black"] ;    GUI_UPDATE_IDLE_TASKS ();  }  IOPbool = 0 ;  Esperienza = IOPG / (totalAgentNum+ciclo) ; // ***  if([uniformDblRand getDoubleWithMin: 0.0                              withMax: 1.0]-Esperienza< [model getProbIOPSuccess])   return investment * [model getIOPmultiplier] ; // ***  IOPG++ ;   return 0.0 ;}-(int) incident {  if([fromList getCount])    return 1 ;  else     return 0 ;}-(int) countInvestors {   id index,aLink ;   int count ;   count = 0 ;   index = [fromList begin: [self getZone]] ;   while( (aLink = [index next]) )     if([aLink isInvestLink])       count++ ;   [index drop] ;   return count ;}-(int) countBorrowers {   id index,aLink ;   int count ;   count = 0 ;   index = [fromList begin: [self getZone]] ;   while( (aLink = [index next]) )     if([aLink isBorrowLink])       count++ ;   [index drop] ;   return count ;   }-(double) getInvestorLinkProbability {  return ((double) [self countInvestors]) / ((double) totalAgentNum) ;}-(double) getBorrowLinkProbability {  return ((double) [self countBorrowers]) / ((double) totalAgentNum) ;}-lend{    double amountLoaned, cumulativeResult, cumulativeResultL ;  id index, link, someone ;  // less than amountLoaned  // this represents the potential  // loan assuming an extra client  prevCapital = capital / (loanCount + 1) ;     cumulativeResultL = 0.0; // ***                                             if(loanCount){    cumulativeResultL = 0.0; // ***    cumulativeResult = 0.0 ;       TranCost=(TranCostBas*2)/IOPG+(TranCostBas*10)/capital; // ***    amountLoaned = (double) capital / (double) loanCount ;    index = [fromList begin: globalZone] ;    while( (link = [index next]) ){      someone = [link getFrom] ;      if([someone borrowingFrom: self]){        double partial ;        partial = [someone generateROI: amountLoaned] ;        cumulativeResultL += partial ; // ***           }  }    cumulativeResult = cumulativeResultL-(TranCost*loanCount) ; // ***        [index drop];  } else {    cumulativeResult = capital;   }   if(investCount)    prevROI = floor(0.5 + (cumulativeResult / ((double)investCount))) ;  else     prevROI = Income ; // ***  investCount = 0 ;  loanCount = 0 ;    return self ;}@end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -