• 大小: 8.69MB
    文件类型: .gz
    金币: 1
    下载: 0 次
    发布日期: 2023-10-17
  • 语言: 其他
  • 标签: sumo  vanet  ns2  

资源简介

SUMO Simulation of Urban MObility is an open source highly portable microscopic and continuous road traffic simulation package designed to handle large road networks It is mainly developed by employees of the Institute of Transportation Systems at the German Aerospace Center SUMO is open source licensed under the GPL ">SUMO Simulation of Urban MObility is an open source highly portable microscopic and continuous road traffic simulation package designed to handle large road networks It is mainly developed by employees of the Institute of Transportation Systems at the German Aerospace Center SUMO is open sourc [更多]

资源截图

代码片段和文件信息

#!/usr/bin/env python
“““
@file    agentManager.py
@author  Michael Behrisch
@author  Daniel Krajzewicz
@date    2008-10-09
@version $Id: agentManager.py 14678 2013-09-11 08:53:06Z behrisch $

Control the CityMobil parking lot with a multi agent system.

SUMO Simulation of Urban MObility; see http://sumo.sourceforge.net/
Copyright (C) 2008-2012 DLR (http://www.dlr.de/) and contributors

This file is part of SUMO.
SUMO is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License or
(at your option) any later version.
“““
import vehicleControl statistics
from constants import *

class PersonAgent:
    def __init__(self id):
        self.id = id
        
    def startRequest(self source target cybers):
        minCost = INFINITY
        minCar = None
        for car in cybers:
            cost = car.request(self source target) 
            if (cost < minCost):
                if minCar:
                    minCar.reject(self)
                minCar = car
                minCost = cost
            else:
                car.reject(self)
        minCar.accept(self)

class Task:
    def __init__(self person source target estCost):
        self.person = person
        self.source = source
        self.target = target
        self.estCost = estCost
        self.startStep = None
        
    def __repr__(self):
        return “<%s %s %s %s>“ % (self.person.id self.source self.target self.startStep)

class CyberAgent:
    def __init__(self id):
        self.id = id
        self.load = 0
        self.pending = {}
        self.tasks = []
        self.running = []
        self.costMatrix = {}
        self.totalEstimatedCost = 0
        self.position = None
        self.broken = False
        
    def request(self person source target):
        if self.broken:
            estCost = INFINITY
        elif (source target) in self.costMatrix:
            estCost = self.costMatrix[(source target)]
        else:
            estCost = 2 * DOUBLE_ROWS * ROW_DIST / CYBER_SPEED
        self.pending[person] = Task(person source target estCost)
        return self.totalEstimatedCost + estCost

    def accept(self person):
        task = self.pending[person]
        self.tasks.append(task)
        self.totalEstimatedCost += task.estCost
        del self.pending[person]

    def reject(self person):
        del self.pending[person]
                    

    def _findNextTarget(self wait):
        minTarget = “z“
        minDownstreamTarget = “z“
        minSource = “z“
        minDownstreamSource = “z“
        edge = vehicleControl.getPosition(self.id)
        if edge == “cyberin“:
            edge = “cyber“
        for task in self.running:
            if task.target < minTarget:
                minTarget = task.target
            if task.target < minDownstreamTarget and task.target > edge:
                minDownstreamTar

评论

共有 条评论