Esempio n. 1
0
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 _ 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 _ 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 _ 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)
Esempio n. 2
0
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 _ 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)
Esempio n. 3
0
    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
Esempio n. 4
0
    def __init__(self, stime, etime=None, iv_id=None):
        """ Create a variable to use for time constraints

        Args:
            stime -- float, the interval start time
            etime -- float, the interval end time
            ade_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 = iv_id or GenName('TV')
Esempio n. 5
0
    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
Esempio n. 6
0
    def __init__(self, details, stimevar, etimevar, duration = 0.01, pe_id = None) :
        self.Details = details
        self.EventID = pe_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
Esempio n. 7
0
    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
Esempio n. 8
0
 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')
Esempio n. 9
0
    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
Esempio n. 10
0
def GenNodeName(prefix = 'node') :
    return GenName(prefix)
Esempio n. 11
0
 def __init__(self):
     self.ConstraintID = GenName('CONSTRAINT')
Esempio n. 12
0
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)