本文整理汇总了C++中NBNetBuilder类的典型用法代码示例。如果您正苦于以下问题:C++ NBNetBuilder类的具体用法?C++ NBNetBuilder怎么用?C++ NBNetBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NBNetBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loader
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods (interface in this case)
// ---------------------------------------------------------------------------
void
NIImporter_ArcView::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
if (!oc.isSet("shapefile-prefix")) {
return;
}
// check whether the correct set of entries is given
// and compute both file names
std::string dbf_file = oc.getString("shapefile-prefix") + ".dbf";
std::string shp_file = oc.getString("shapefile-prefix") + ".shp";
std::string shx_file = oc.getString("shapefile-prefix") + ".shx";
// check whether the files do exist
if (!FileHelpers::isReadable(dbf_file)) {
WRITE_ERROR("File not accessible: " + dbf_file);
}
if (!FileHelpers::isReadable(shp_file)) {
WRITE_ERROR("File not accessible: " + shp_file);
}
if (!FileHelpers::isReadable(shx_file)) {
WRITE_ERROR("File not accessible: " + shx_file);
}
if (MsgHandler::getErrorInstance()->wasInformed()) {
return;
}
// load the arcview files
NIImporter_ArcView loader(oc,
nb.getNodeCont(), nb.getEdgeCont(), nb.getTypeCont(),
dbf_file, shp_file, oc.getBool("speed-in-kmh"));
loader.load();
}
示例2: handler
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods (interface in this case)
// ---------------------------------------------------------------------------
void
NIImporter_RobocupRescue::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// check whether the option is set (properly)
if (!oc.isSet("robocup-dir")) {
return;
}
// build the handler
NIImporter_RobocupRescue handler(nb.getNodeCont(), nb.getEdgeCont());
// parse file(s)
std::vector<std::string> files = oc.getStringVector("robocup-dir");
for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
// nodes
std::string nodesName = (*file) + "/node.bin";
if (!FileHelpers::exists(nodesName)) {
WRITE_ERROR("Could not open robocup-node-file '" + nodesName + "'.");
return;
}
PROGRESS_BEGIN_MESSAGE("Parsing robocup-nodes from '" + nodesName + "'");
handler.loadNodes(nodesName);
PROGRESS_DONE_MESSAGE();
// edges
std::string edgesName = (*file) + "/road.bin";
if (!FileHelpers::exists(edgesName)) {
WRITE_ERROR("Could not open robocup-road-file '" + edgesName + "'.");
return;
}
PROGRESS_BEGIN_MESSAGE("Parsing robocup-roads from '" + edgesName + "'");
handler.loadEdges(edgesName);
PROGRESS_DONE_MESSAGE();
}
}
示例3: nodesHandler
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
void
NIImporter_MATSim::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// check whether the option is set (properly)
if (!oc.isSet("matsim-files")) {
return;
}
/* Parse file(s)
* Each file is parsed twice: first for nodes, second for edges. */
std::vector<std::string> files = oc.getStringVector("matsim-files");
// load nodes, first
NodesHandler nodesHandler(nb.getNodeCont());
for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
// nodes
if (!FileHelpers::isReadable(*file)) {
WRITE_ERROR("Could not open matsim-file '" + *file + "'.");
return;
}
nodesHandler.setFileName(*file);
PROGRESS_BEGIN_MESSAGE("Parsing nodes from matsim-file '" + *file + "'");
if (!XMLSubSys::runParser(nodesHandler, *file)) {
return;
}
PROGRESS_DONE_MESSAGE();
}
// load edges, then
EdgesHandler edgesHandler(nb.getNodeCont(), nb.getEdgeCont(), oc.getBool("matsim.keep-length"),
oc.getBool("matsim.lanes-from-capacity"), NBCapacity2Lanes(oc.getFloat("lanes-from-capacity.norm")));
for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
// edges
edgesHandler.setFileName(*file);
PROGRESS_BEGIN_MESSAGE("Parsing edges from matsim-file '" + *file + "'");
XMLSubSys::runParser(edgesHandler, *file);
PROGRESS_DONE_MESSAGE();
}
}
示例4: main
/* -------------------------------------------------------------------------
* main
* ----------------------------------------------------------------------- */
int
main(int argc, char** argv) {
OptionsCont& oc = OptionsCont::getOptions();
// give some application descriptions
oc.setApplicationDescription("Road network importer / builder for the road traffic simulation SUMO.");
oc.setApplicationName("netconvert", "SUMO netconvert Version " + (std::string)VERSION_STRING);
int ret = 0;
try {
XMLSubSys::init(false);
fillOptions();
OptionsIO::getOptions(true, argc, argv);
if (oc.processMetaOptions(argc < 2)) {
SystemFrame::close();
return 0;
}
MsgHandler::initOutputOptions();
if (!checkOptions()) {
throw ProcessError();
}
RandHelper::initRandGlobal();
NBNetBuilder nb;
nb.applyOptions(oc);
// load data
NILoader nl(nb);
nl.load(oc);
if (oc.getBool("ignore-errors")) {
MsgHandler::getErrorInstance()->clear();
}
// check whether any errors occured
if (MsgHandler::getErrorInstance()->wasInformed()) {
throw ProcessError();
}
nb.compute(oc);
if(oc.getAnyVerbosity())
std::cout<<"Writing output file..."<<std::endl;
NWFrame::writeNetwork(oc, nb);
if(oc.getAnyVerbosity())
std::cout<<"Output file writed"<<std::endl;
} catch (ProcessError& e) {
if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
WRITE_ERROR(e.what());
}
MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
ret = 1;
#ifndef _DEBUG
} catch (...) {
MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
ret = 1;
#endif
}
NBDistribution::clear();
OutputDevice::closeAll();
SystemFrame::close();
// report about ending
if (ret == 0) {
std::cout << "Success." << std::endl;
}
return ret;
}
示例5: writeNodesUnsplitted
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
void
NWWriter_DlrNavteq::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// check whether a matsim-file shall be generated
if (!oc.isSet("dlr-navteq-output")) {
return;
}
writeNodesUnsplitted(oc, nb.getNodeCont(), nb.getEdgeCont());
writeLinksUnsplitted(oc, nb.getEdgeCont());
}
示例6: SUMOSAXHandler
// ---------------------------------------------------------------------------
// loader methods
// ---------------------------------------------------------------------------
NIImporter_SUMO::NIImporter_SUMO(NBNetBuilder& nb)
: SUMOSAXHandler("sumo-network"),
myNetBuilder(nb),
myNodeCont(nb.getNodeCont()),
myTLLCont(nb.getTLLogicCont()),
myCurrentEdge(0),
myCurrentLane(0),
myCurrentTL(0),
myLocation(0),
mySuspectKeepShape(false) {}
示例7: main
int
main(int argc, char** argv) {
OptionsCont& oc = OptionsCont::getOptions();
// give some application descriptions
oc.setApplicationDescription("Road network generator for the microscopic road traffic simulation SUMO.");
oc.setApplicationName("netgen", "SUMO netgen Version " + (std::string)VERSION_STRING);
int ret = 0;
try {
// initialise the application system (messaging, xml, options)
XMLSubSys::init(false);
fillOptions();
OptionsIO::getOptions(true, argc, argv);
if (oc.processMetaOptions(argc < 2)) {
SystemFrame::close();
return 0;
}
MsgHandler::initOutputOptions();
if (!checkOptions()) {
throw ProcessError();
}
RandHelper::initRandGlobal();
NBNetBuilder nb;
nb.applyOptions(oc);
// build the netgen-network description
NGNet* net = buildNetwork(nb);
// ... and we have to do this...
oc.resetWritable();
// transfer to the netbuilding structures
net->toNB();
delete net;
// report generated structures
WRITE_MESSAGE(" Generation done;");
WRITE_MESSAGE(" " + toString<int>(nb.getNodeCont().size()) + " nodes generated.");
WRITE_MESSAGE(" " + toString<int>(nb.getEdgeCont().size()) + " edges generated.");
nb.compute(oc);
NWFrame::writeNetwork(oc, nb);
} catch (ProcessError& e) {
if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
WRITE_ERROR(e.what());
}
MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
ret = 1;
#ifndef _DEBUG
} catch (...) {
MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
ret = 1;
#endif
}
OutputDevice::closeAll();
SystemFrame::close();
if (ret == 0) {
std::cout << "Success." << std::endl;
}
return ret;
}
示例8: SUMOSAXHandler
// ---------------------------------------------------------------------------
// loader methods
// ---------------------------------------------------------------------------
NIImporter_SUMO::NIImporter_SUMO(NBNetBuilder& nb)
: SUMOSAXHandler("sumo-network"),
myNetBuilder(nb),
myNodeCont(nb.getNodeCont()),
myTLLCont(nb.getTLLogicCont()),
myCurrentEdge(0),
myCurrentLane(0),
myCurrentTL(0),
myLocation(0),
mySuspectKeepShape(false),
myHaveWarnedAboutDeprecatedSpreadType(false),
myHaveWarnedAboutDeprecatedMaxSpeed(false) {}
示例9: SUMOSAXHandler
// ---------------------------------------------------------------------------
// loader methods
// ---------------------------------------------------------------------------
NIImporter_SUMO::NIImporter_SUMO(NBNetBuilder& nb)
: SUMOSAXHandler("sumo-network"),
myNetBuilder(nb),
myNodeCont(nb.getNodeCont()),
myTLLCont(nb.getTLLogicCont()),
myCurrentEdge(0),
myCurrentLane(0),
myCurrentTL(0),
myLocation(0),
myHaveSeenInternalEdge(false),
myAmLefthand(false),
myCornerDetail(0),
myLinkDetail(-1) {
}
示例10: buildOnRamp
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// NBRampsComputer
// ---------------------------------------------------------------------------
void
NBRampsComputer::computeRamps(NBNetBuilder& nb, OptionsCont& oc) {
SUMOReal minHighwaySpeed = oc.getFloat("ramps.min-highway-speed");
SUMOReal maxRampSpeed = oc.getFloat("ramps.max-ramp-speed");
SUMOReal rampLength = oc.getFloat("ramps.ramp-length");
bool dontSplit = oc.getBool("ramps.no-split");
std::set<NBEdge*> incremented;
// check whether on-off ramps shall be guessed
if (oc.getBool("ramps.guess")) {
NBNodeCont& nc = nb.getNodeCont();
NBEdgeCont& ec = nb.getEdgeCont();
NBDistrictCont& dc = nb.getDistrictCont();
std::set<NBNode*> potOnRamps;
std::set<NBNode*> potOffRamps;
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
NBNode* cur = (*i).second;
if (mayNeedOnRamp(cur, minHighwaySpeed, maxRampSpeed)) {
potOnRamps.insert(cur);
}
if (mayNeedOffRamp(cur, minHighwaySpeed, maxRampSpeed)) {
potOffRamps.insert(cur);
}
}
for (std::set<NBNode*>::const_iterator i = potOnRamps.begin(); i != potOnRamps.end(); ++i) {
buildOnRamp(*i, nc, ec, dc, rampLength, dontSplit, incremented);
}
for (std::set<NBNode*>::const_iterator i = potOffRamps.begin(); i != potOffRamps.end(); ++i) {
buildOffRamp(*i, nc, ec, dc, rampLength, dontSplit, incremented);
}
}
// check whether on-off ramps shall be guessed
if (oc.isSet("ramps.set")) {
std::vector<std::string> edges = oc.getStringVector("ramps.set");
NBNodeCont& nc = nb.getNodeCont();
NBEdgeCont& ec = nb.getEdgeCont();
NBDistrictCont& dc = nb.getDistrictCont();
for (std::vector<std::string>::iterator i = edges.begin(); i != edges.end(); ++i) {
NBEdge* e = ec.retrieve(*i);
if (e == 0) {
WRITE_WARNING("Can not build on ramp on edge '" + *i + "' - the edge is not known.");
continue;
}
NBNode* from = e->getFromNode();
if (from->getIncomingEdges().size() == 2 && from->getOutgoingEdges().size() == 1) {
buildOnRamp(from, nc, ec, dc, rampLength, dontSplit, incremented);
}
// load edge again to check offramps
e = ec.retrieve(*i);
if (e == 0) {
WRITE_WARNING("Can not build off ramp on edge '" + *i + "' - the edge is not known.");
continue;
}
NBNode* to = e->getToNode();
if (to->getIncomingEdges().size() == 1 && to->getOutgoingEdges().size() == 2) {
buildOffRamp(to, nc, ec, dc, rampLength, dontSplit, incremented);
}
}
}
}
示例11:
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
void
NWWriter_MATSim::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// check whether a matsim-file shall be generated
if (!oc.isSet("matsim-output")) {
return;
}
OutputDevice& device = OutputDevice::getDevice(oc.getString("matsim-output"));
device << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
device << "<!DOCTYPE network SYSTEM \"http://www.matsim.org/files/dtd/network_v1.dtd\">\n\n";
device << "<network name=\"NAME\">\n"; // !!! name
// write nodes
device << " <nodes>\n";
NBNodeCont& nc = nb.getNodeCont();
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
device << " <node id=\"" << (*i).first
<< "\" x=\"" << (*i).second->getPosition().x()
<< "\" y=\"" << (*i).second->getPosition().y()
<< "\"/>\n";
}
device << " </nodes>\n";
// write edges
device << " <links capperiod=\"01:00:00\">\n";
NBEdgeCont& ec = nb.getEdgeCont();
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
device << " <link id=\"" << (*i).first
<< "\" from=\"" << (*i).second->getFromNode()->getID()
<< "\" to=\"" << (*i).second->getToNode()->getID()
<< "\" length=\"" << (*i).second->getLoadedLength()
<< "\" capacity=\"" << (oc.getFloat("lanes-from-capacity.norm") * (*i).second->getNumLanes())
<< "\" freespeed=\"" << (*i).second->getSpeed()
<< "\" permlanes=\"" << (*i).second->getNumLanes()
<< "\"/>\n";
}
device << " </links>\n";
//
device << "</network>\n"; // !!! name
device.close();
}
示例12:
void
NWFrame::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
NWWriter_SUMO::writeNetwork(oc, nb);
NWWriter_MATSim::writeNetwork(oc, nb);
NWWriter_OpenDrive::writeNetwork(oc, nb);
NWWriter_DlrNavteq::writeNetwork(oc, nb);
NWWriter_XML::writeNetwork(oc, nb);
// save the mapping information when wished
if (oc.isSet("map-output")) {
OutputDevice& mdevice = OutputDevice::getDevice(oc.getString("map-output"));
mdevice << nb.getJoinedEdgesMap();
mdevice.close();
}
}
示例13: writeNodesUnsplitted
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
void
NWWriter_DlrNavteq::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// check whether a matsim-file shall be generated
if (!oc.isSet("dlr-navteq-output")) {
return;
}
std::map<NBEdge*, std::string> internalNodes;
writeNodesUnsplitted(oc, nb.getNodeCont(), nb.getEdgeCont(), internalNodes);
writeLinksUnsplitted(oc, nb.getEdgeCont(), internalNodes);
writeTrafficSignals(oc, nb.getNodeCont());
writeProhibitedManoeuvres(oc, nb.getNodeCont(), nb.getEdgeCont());
writeConnectedLanes(oc, nb.getNodeCont());
}
示例14: writeNodes
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
void
NWWriter_XML::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// check whether plain-output files shall be generated
if (oc.isSet("plain-output-prefix")) {
writeNodes(oc, nb.getNodeCont());
writeEdgesAndConnections(oc, nb.getNodeCont(), nb.getEdgeCont());
writeTrafficLights(oc, nb.getTLLogicCont(), nb.getEdgeCont());
}
if (oc.isSet("junctions.join-output")) {
writeJoinedJunctions(oc, nb.getNodeCont());
}
if (oc.isSet("street-sign-output")) {
writeStreetSigns(oc, nb.getEdgeCont());
}
}
示例15: writeLocation
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
void
NWWriter_SUMO::writeNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// check whether a sumo net-file shall be generated
if (!oc.isSet("output-file")) {
return;
}
OutputDevice& device = OutputDevice::getDevice(oc.getString("output-file"));
device.writeXMLHeader("net", NWFrame::MAJOR_VERSION + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://sumo.sf.net/xsd/net_file.xsd\""); // street names may contain non-ascii chars
device.lf();
// get involved container
const NBNodeCont& nc = nb.getNodeCont();
const NBEdgeCont& ec = nb.getEdgeCont();
const NBDistrictCont& dc = nb.getDistrictCont();
// write network offsets and projection
writeLocation(device);
// write inner lanes
bool origNames = oc.getBool("output.original-names");
if (!oc.getBool("no-internal-links")) {
bool hadAny = false;
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
hadAny |= writeInternalEdges(device, *(*i).second, origNames);
}
if (hadAny) {
device.lf();
}
}
// write edges with lanes and connected edges
bool noNames = !oc.getBool("output.street-names");
for (std::map<std::string, NBEdge*>::const_iterator i = ec.begin(); i != ec.end(); ++i) {
writeEdge(device, *(*i).second, noNames, origNames);
}
device.lf();
// write tls logics
writeTrafficLights(device, nb.getTLLogicCont());
// write the nodes (junctions)
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
writeJunction(device, *(*i).second);
}
device.lf();
const bool includeInternal = !oc.getBool("no-internal-links");
if (includeInternal) {
// ... internal nodes if not unwanted
bool hadAny = false;
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
hadAny |= writeInternalNodes(device, *(*i).second);
}
if (hadAny) {
device.lf();
}
}
// write the successors of lanes
unsigned int numConnections = 0;
for (std::map<std::string, NBEdge*>::const_iterator it_edge = ec.begin(); it_edge != ec.end(); it_edge++) {
NBEdge* from = it_edge->second;
from->sortOutgoingConnectionsByIndex();
const std::vector<NBEdge::Connection> connections = from->getConnections();
numConnections += (unsigned int)connections.size();
for (std::vector<NBEdge::Connection>::const_iterator it_c = connections.begin(); it_c != connections.end(); it_c++) {
writeConnection(device, *from, *it_c, includeInternal);
}
}
if (numConnections > 0) {
device.lf();
}
if (includeInternal) {
// ... internal successors if not unwanted
bool hadAny = false;
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
hadAny |= writeInternalConnections(device, *(*i).second);
}
if (hadAny) {
device.lf();
}
}
// write loaded prohibitions
for (std::map<std::string, NBNode*>::const_iterator i = nc.begin(); i != nc.end(); ++i) {
writeProhibitions(device, i->second->getProhibitions());
}
// write roundabout information
const std::vector<EdgeVector>& roundabouts = nb.getRoundabouts();
for (std::vector<EdgeVector>::const_iterator i = roundabouts.begin(); i != roundabouts.end(); ++i) {
writeRoundabout(device, *i);
}
if (roundabouts.size() != 0) {
device.lf();
}
//.........这里部分代码省略.........