def PlaceBusinesses(): global world pweights = WeightedChoice() profiles = {} for profname, profile in world.IterNodes(nodetype='BusinessProfile'): pweights.AddChoice(profname, ProfileWeights.get(profname, 2)) profiles[profname] = profile # add some factories factory = profiles['large-factory'] for i in range(8): name = GenName('large-factory') business = world.AddBusiness(name, ScaleProfile(factory)) location = PlaceBusiness(business) if not location: world.DropNode(business) break # add some factories school = profiles['high-school'] for i in range(2): name = GenName('high-school') business = world.AddBusiness(name, ScaleProfile(school)) location = PlaceBusiness(business) if not location: world.DropNode(business) break # add some large services service = profiles['large-service'] for i in range(2): name = GenName('large-service') business = world.AddBusiness(name, ScaleProfile(service)) location = PlaceBusiness(business) if not location: world.DropNode(business) break # and fill in with more random businesses while len(profiles) > 0: # this is a uniform distribution of businesses from the options # pname = random.choice(profiles.keys()) pname = pweights.Choose() profile = profiles[pname] name = GenName(pname) business = world.AddBusiness(name, ScaleProfile(profile)) location = PlaceBusiness(business) # if we could not place the business, then all locations # have fitness of 0... so don't try again if not location: world.DropNode(business) del profiles[pname] pweights.DropChoice(pname)
def __init__(self, srcplace, dstplace, estimator=None, te_id=None): self.SrcPlace = srcplace self.DstPlace = dstplace self.Duration = estimator.ComputeTravelTime( srcplace.Details, dstplace.Details) if estimator else self.DefaultDuration self.EventID = te_id or GenName('TRAVEL')
def PlacePeople(): global world profile = world.FindNodeByName('worker') bizlist = {} for name, biz in world.IterNodes(nodetype='Business'): bizlist[name] = biz people = 0 for name, biz in bizlist.iteritems(): bprof = biz.EmploymentProfile for job, demand in bprof.JobList.iteritems(): for p in range(0, demand): people += 1 name = GenName(wprof.Name) person = world.AddPerson(name, wprof) world.SetEmployer(person, biz) SocialNodes.Person.SetJob(person, job) SocialNodes.Person.SetVehicle( person, wprof.VehicleType.PickVehicleType()) SetRulePreferences(person) location = PlacePerson(person) if not location: logger.warn('ran out of residences after %d people', people) return logger.info('created %d people', people)
def SetVehicle(person, vehicletype) : """ Args: person -- object of type Person job -- object of type SocialDecoration.JobDescription """ name = GenName('veh' + vehicletype) person.AddDecoration(SocialDecoration.VehicleDecoration(name, vehicletype)) return name
def __init__(self, details, stimevar, etimevar, duration=0.01, ade_id=None): PlaceEvent.__init__(self, details, stimevar, etimevar, duration, ade_id) self.MinimumSplitDuration = duration self.AggregateID = GenName('AGGREGATE') self.AggregateHead = True
def __init__(self, stime, etime=None, id=None): """ Create a variable to use for time constraints Args: stime -- float, the interval start time etime -- float, the interval end time id -- unique identifier for the time variable """ self.IntervalStart = float(min(stime, etime or stime)) self.IntervalEnd = float(max(stime, etime or stime)) self.ID = id or GenName('TV')
def AddResidentialLocation(self, profname, endpoints): """ Args: profname -- string name of the business location profile collection endpoints -- list of endpoint objects of type LayoutNodes.Endpoint """ profile = self.Nodes[profname] if profile.NodeType.Name != LayoutNodes.ResidentialLocationProfile.__name__: raise ValueError( 'Invalid residential location profile name; {0}'.format( profname)) location = LayoutNodes.ResidentialLocation(GenName('rezloc'), profile) WorldInfo.WorldInfo.AddResidentialLocation(self, location) # residential locations have one endpoint per capsule for endpoint in endpoints: capsule = LayoutNodes.LocationCapsule(GenName('rezcap')) WorldInfo.WorldInfo.AddLocationCapsule(self, capsule) capsule.AddEndPointToCapsule(endpoint) location.AddCapsuleToLocation(capsule) return location
def __init__(self, details, stimevar, etimevar, duration = 0.01, id = None) : self.Details = details self.EventID = id or GenName('PLACE') # EventStart and EventEnd properties contain the original interval definitions, all # constraint resolution will happen on copies of these variables stored # EventStart and EventEnd properties. self.BaseEventStart = stimevar self.BaseEventEnd = etimevar self.Reset() # Duration is the minimum duration of the event self.Duration = max(duration, 0.01) # Arrival and Departure properties connect this event into an # ordered chain of events self.Arrival = None self.Departure = None
def __init__(self, traveler, stime, source, destination): """ Args: traveler -- object of type Traveler stime -- float, world time at the start of the trip source -- LayoutNodes.LocationCapsule destination -- LayoutNodes.LocationCapsule """ self.Traveler = traveler self.ScheduledStartTime = stime self.ActualStartTime = 0 self.Source = source self.Destination = destination # the vehicle name should come from the person, however Sumo # does not generate create events when a vehicle name is reused self.TripID = GenName(self.Traveler.Person.Name + '_trip') self.VehicleName = self.TripID self.VehicleType = self.Traveler.Person.Vehicle.VehicleType
def ScaleProfile(profile): scale = GenWeight(1.0, 0.5, 0.5, 3.0) offset = GenWeight(0.0, 0.2, -1.5, 1.5) name = GenName('sp_' + profile.Name) return world.AddScaledBusinessProfile(name, profile, scale, offset)
def __init__(self): self.ConstraintID = GenName('CONSTRAINT')
def GenNodeName(prefix='node'): return GenName(prefix)