示例#1
0
def makeWanderer():
    return {'location': data.makeOrbisLocation(50327),
            'state':wanderSelectDestination,
            'current_time': 0.0,
            'destination': data.Location(),
            'last_city': data.Location(),
            'previous_locations': list(),
            'journey':{'type':'', 'distance':'0.0', 'expense':'0.0', 'days':'0.0'}}
示例#2
0
def scoreEdgesByVisits(wander, edges) -> dict:
    visits = countVisits(wander)
    edge_loc = [data.makeOrbisLocation(i['target']) for i in edges]
    score = []
    for i in edge_loc:
        try:
            score.append(visits[i.id()])
        except KeyError:
            score.append(0)
    prob_max = max(1.0, max(score)) + 1
    prob = numpy.array([(max(0, prob_max - i) / prob_max) for i in score])
    prob /= prob.sum()
    #print(prob)
    return prob
示例#3
0
def scoreEdgesByVisits(wander, edges) -> dict:
    visits = countVisits(wander)
    edge_loc = [data.makeOrbisLocation(i['target']) for i in edges]
    score = []
    for i in edge_loc:
        try:
            score.append(visits[i.id()])
        except KeyError:
            score.append(0)
    prob_max = max(1.0, max(score)) + 1
    prob = numpy.array([(max(0, prob_max - i) / prob_max) for i in score])
    prob /= prob.sum()
    #print(prob)
    return prob
示例#4
0
def makeWanderer():
    return {
        'location': data.makeOrbisLocation(50327),
        'state': wanderSelectDestination,
        'current_time': 0.0,
        'destination': data.Location(),
        'last_city': data.Location(),
        'previous_locations': list(),
        'journey': {
            'type': '',
            'distance': '0.0',
            'expense': '0.0',
            'days': '0.0'
        }
    }
示例#5
0
def wanderSelectDestination(wander):
    """
    The wanderer needs to select the next destination.
    """
    if DISPLAY_WANDERING_PROGRESS:
        print("wanderSelectDestination")
    current = data.hydrateLocation(wander['location']).orbis_id
    edges = data.findOrbisEdges(current)
    weighted_edges = scoreEdgesByVisits(wander, edges)
    #weighted_edges = data.scoreByDistance(data.hydrateLocation(wander['location']), edges)
    try:
        #destination = random.choice(edges)
        destination = settings.TRAVEL_RNG.choice(edges, p=weighted_edges)
    except Exception as err:
        print (err)
        return
    wander['destination'] = data.hydrateLocation(data.makeOrbisLocation(destination['target']))
    wander['journey'] = destination
    wander['last_city'] = data.hydrateLocation(wander['location'])
    wander['state'] = wanderTravel
    renderSelectDestination(wander)
    return wander
示例#6
0
def wanderSelectDestination(wander):
    """
    The wanderer needs to select the next destination.
    """
    if DISPLAY_WANDERING_PROGRESS:
        print("wanderSelectDestination")
    current = data.hydrateLocation(wander['location']).orbis_id
    edges = data.findOrbisEdges(current)
    weighted_edges = scoreEdgesByVisits(wander, edges)
    #weighted_edges = data.scoreByDistance(data.hydrateLocation(wander['location']), edges)
    try:
        #destination = random.choice(edges)
        destination = settings.TRAVEL_RNG.choice(edges, p=weighted_edges)
    except Exception as err:
        print(err)
        return
    wander['destination'] = data.hydrateLocation(
        data.makeOrbisLocation(destination['target']))
    wander['journey'] = destination
    wander['last_city'] = data.hydrateLocation(wander['location'])
    wander['state'] = wanderTravel
    renderSelectDestination(wander)
    return wander