コード例 #1
0
ファイル: flee_sanne.py プロジェクト: sannedonker/CSS_Group2
    def evolve(self):
        # update level 1, 2 and 3 location scores
        for l in self.locations:
            l.time = self.time
            l.updateLocationScore()

        for l in self.locations:
            l.updateNeighbourhoodScore()

        for l in self.locations:
            l.updateRegionScore()

        # update agent locations
        for a in self.agents:
            a.evolve()

        for a in self.agents:
            a.finish_travel()
            a.timesteps_since_departure += 1
            a.recent_travel_distance = (
                a.recent_travel_distance +
                (a.distance_moved_this_timestep /
                 SimulationSettings.MaxMoveSpeed)) / 2.0
            a.distance_moved_this_timestep = 0

        # update link properties
        if SimulationSettings.CampLogLevel > 0:
            self._aggregate_arrivals()

        if SimulationSettings.AgentLogLevel > 0:
            write_agents(self.agents, self.time)

        self.time += 1
コード例 #2
0
    def evolve(self) :
    
            for l in self.locations :
                l.time = self.time
                l.updateLocationScore()
            for l in self.locations :
                l.updateNeighbourhoodScore()
            for l in self.locations :
                l.updateRegionScore()
                
            '''
            Divide groups into to two at 5% of all locations, at each time step
            '''
                
            locs=[gr.location for gr in self.agents if not isinstance(gr.location, Link )]
            sample_locs=random.sample(list(locs),int(len(locs)*0.005))

            
            for loc in sample_locs:
                
                    all_group_locs = [group for group in self.agents if group.location==loc ] 
                    

                    old_group=random.choice(all_group_locs)
                        
                    size_of_old_group = old_group.size
                    
                    rand=random.random()
                    new_size1 = int(size_of_old_group*rand)
                    new_size2 = int(size_of_old_group*(1-rand))
                    

                         
                    # remove old group from the location and two new ones
                    
                    [old_group.location.DecrementNumAgents() for i in range(size_of_old_group)]                
                    
                   
                    self.addAgent(old_group.location, new_size1)
                    self.addAgent(old_group.location, new_size2)
    
    
            
            for a in self.agents :
                a.evolve()
                
    
            for a in self.agents :
                a.finish_travel()
            a.timesteps_since_departure += 1
            a.recent_travel_distance = (a.recent_travel_distance + (
                        a.distance_moved_this_timestep / a.move_speed)) / 2.0
            a.distance_moved_this_timestep = 0

        # update link properties
            if SimulationSettings.CampLogLevel > 0 :
                self._aggregate_arrivals()
    
            if SimulationSettings.AgentLogLevel > 0 :
                write_agents(self.agents, self.time)

            self.time += 1