コード例 #1
0
ファイル: env.py プロジェクト: tommyblizzard/testrep
    def importAgents(self):
        '''
            Function to import agents from a file previously prepared

        '''
        print '\n|- AGENTS IMPORT PROCESS...'
        # file name
        tmpFileName = os.path.join(self.simPath, 'initAgents.csv')

        try:
            fileFID = open(tmpFileName, 'r')
        except:
            print "Technology file has not been found: ", tmpFileName;
            sys.exit(1)

        # read file
        agents = fileFID.readlines()

        # for each Agent
        for a in agents:
            if a[0] != '#':
                tmpID, tmpX, tmpY, tmpEN, tmpHA, tmpSolPot, tmpCO2, tmpSocialLobby, tmpintCap, \
                tmpEquity, tmpBalance, tmpMbalance, tmpInvL, tmpHealth, tmpAge = a.split()
                # Insert Agent

                self.allAgents.append(
                    ag.agents(self.debugLevel, int(tmpID), float(tmpX), float(tmpY), float(tmpEN), float(tmpHA),
                              float(tmpSocialLobby), \
                              float(tmpSolPot), float(tmpEquity), float(tmpintCap), int(tmpInvL), float(tmpHealth), 55,
                              int(tmpAge), None, None, None, None, \
                              float(tmpBalance), float(tmpMbalance), None, None, None, None, None))

        fileFID.close()
        print ' |- done...'
コード例 #2
0
ファイル: env.py プロジェクト: tommyblizzard/testrep
    def createPopulation(self):
        '''
            Function to create the population

            To assign the social lobby parameter (1-sociallobby is the committiment) the beta distribution is used.
        '''
        # if agentCreationMethod is equal to 0 random population is created otherwise it is uploaded from file
        if self.agentCreationMethod == 0:
            sl = []
            for i in range(0, self.Nagents):
                if self.H == 1:
                    tmprndHealth = (0.1 * np.random.randn(1)) + 0.5
                    if tmprndHealth > 1: tmprndHealth = 1
                    if tmprndHealth < 0: tmprndHealth = 0
                else:
                    tmprndHealth = 0.5
                # Accordind to parameters alpha and beta, the social lobby is provided
                socialLobby = np.random.beta(self.socialLobby_betadist_alpha, self.socialLobby_betadist_beta)
                self.allAgents.append(
                    ag.agents(self.debugLevel, i, ran.uniform(0, self.xMaxPos), ran.uniform(0, self.yMaxPos), \
                              ran.randint(self.minNrgDim, self.maxNrgDim), ran.uniform(0, self.agroMaxDim), \
                              socialLobby, ran.uniform(self.minIrradiation, 1), self.intRiskRate, \
                              self.ratioInternalCapital, self.invLength, tmprndHealth))

        else:
            self.importAgents()

        self.genDistanceLists()
        # self.promptAgents()
        # Compute the overall energy need of the system
        self.computeTotEnergyNeed()