本文整理汇总了C++中Road::getId方法的典型用法代码示例。如果您正苦于以下问题:C++ Road::getId方法的具体用法?C++ Road::getId怎么用?C++ Road::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Road
的用法示例。
在下文中一共展示了Road::getId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
std::vector<double> TrafficNetwork::getMinTTVec(){
std::vector<double>minTTs(Road::roadCounter);
std::vector<long> nIds;
for(NodeVec::iterator it= nodes.begin() ; it!=nodes.end(); ++it){
nIds = (*it)->getNeighborsId();
for(std::vector<long>::iterator jt = nIds.begin(); jt != nIds.end(); ++jt){
Road* r = (*it)->roadTo(*jt);
minTTs[r->getId()]= r->getMinTravelTime();
}
}
return minTTs;
}
示例2: saveToFile
bool TrafficNetwork::saveToFile(const string out_prefix, bool newWeek){
bool everythingOK = true;
int metric = KPH; //save in KPH such that it can be used by external tool (and be human readable)
std::vector<long> nIds;
long crtId;
char crtType;
string out_fileName = (out_prefix+"_roads_stats.json");
json_t *root = NULL;
if(firstSaved){
if(fileName != ""){
json_error_t error;
root = json_load_file(fileName.c_str(), 0, &error);
if(!root){
std::cout<<std::endl<<"WARNING: while opening "<<fileName<<" at line "<<error.line<<" - "<<error.text<<std::endl;
root= NULL;
}
if(!json_is_object(root)){
std::cout<<std::endl<<"WARNING: input file "<<fileName<<" has not the correct structure - expected root to be an object"<<std::endl;
json_decref(root);
root = NULL;
}
if(!root){
std::cout<<"File "<<fileName<<" could not be using during saving process"<<std::endl<<"\t --> reverting to saving network based on stored data (possibility for loss of positional infos)"<<std::endl;
}
}
if(!root){
root = json_object();
if ( root ) {
json_object_set_new(root, "metric" ,json_integer(metric));
json_t *_nodes = json_array();
json_t *_roads = json_array();
for(NodeVec::iterator it= nodes.begin() ; it!=nodes.end(); ++it){
json_t * _node = json_object();
crtId = (*it)->getId();
crtType = (*it)->getType();
json_object_set_new(_node,"id",json_integer(crtId));
json_object_set_new(_node,"type",json_integer(crtType));
json_array_append_new(_nodes,_node);
nIds = (*it)->getNeighborsId();
for(std::vector<long>::iterator jt = nIds.begin(); jt != nIds.end(); ++jt){
Road r = *((*it)->roadTo(*jt));
json_t * _road = json_object();
json_object_set_new(_road,"name",json_string(r.getName().c_str()));
json_object_set_new(_road,"startId",json_integer(crtId));
json_object_set_new(_road,"endId",json_integer(r.getEndPoint()->getId()));
json_object_set_new(_road,"speedLimit",json_integer(r.getSpeedLimit()*3.6)); //x3.6 to go from MPS to KPH
json_object_set_new(_road,"length",json_real(r.getLength()/1000)); // /1000 to go from M to K
json_object_set_new(_road,"nbBands",json_integer(r.getNbBands()));
json_array_append_new(_roads,_road);
}
}
json_object_set_new(root, "nodes" ,_nodes);
json_object_set_new(root, "roads" ,_roads);
}else{
std::cout<<"ERROR: Could not create 'root' during saving process"<<std::endl;
return false;
}
}
}else{
json_error_t error;
root = json_load_file(out_fileName.c_str(), 0, &error);
if(!root){
std::cout<<std::endl<<"ERROR: while opening "<<out_fileName<<" at line "<<error.line<<" - "<<error.text<<std::endl;
root= NULL;
return false;
}
if(!json_is_object(root)){
std::cout<<std::endl<<"ERROR: input file "<<fileName<<" has not the correct structure - expected root to be an object"<<std::endl;
json_decref(root);
root = NULL;
return false;
}
}
json_t *roadsInfos;
if(monitered){
bool first = false;
if(firstSaved){
roadsInfos = json_array();
int nbRoads = json_array_size(json_object_get(root,"roads"));
for(int i = 0; i < nbRoads; i++){
json_array_append_new(roadsInfos,json_object());
}
json_object_set(root,"roadsInfos",roadsInfos);
json_object_set_new(root,"timePrecision",json_integer(TIME_PRECISION));
json_object_set_new(root,"time_index",json_integer(0));
json_object_set_new(root,"driversCount_index",json_integer(1));
firstSaved = false;
//.........这里部分代码省略.........