int main(int argc, char *argv[]){ //into printf("\nThis is the core of a neural net computation:\n"); if(argc != 2){ //check for an input file name printf("Incorrect number of inputs given.\n"); return EXIT_FAILURE; } FILE *fp; //file pointer fp = fopen(argv[1], "r"); //open the given file if(fp == NULL){ //if there was no such file printf("No such file.\n"); return EXIT_FAILURE; } N *net = buildNet(fp); // ~~~~~~~~ Set Initial Input ~~~~~~~~~ // net[0]->potential = 160; net[1]->potential = 160; net[2]->potential = 160; //showNet(net); int i = 0; while(i < NUM_CYCLES){ printf("\t================== This is cycle number %d =================\n", i); cycleNet(net); i++; } //showNet(net); saveNet(net); printf("\n\t=================== End of simulation ========================\n\n"); return EXIT_SUCCESS; }
bool NLBuilder::build() { // try to build the net if (!load("net-file", true)) { return false; } // check whether the loaded net agrees with the simulation options if (myOptions.getBool("no-internal-links") && myXMLHandler.haveSeenInternalEdge()) { WRITE_WARNING("Network contains internal links but option --no-internal-links is set. Vehicles will 'jump' across junctions and thus underestimate route lengths and travel times."); } if (myOptions.getString("lanechange.duration") != "0" && myXMLHandler.haveSeenNeighs()) { throw ProcessError("Network contains explicit neigh lanes which do not work together with option --lanechange.duration."); } buildNet(); // @note on loading order constraints: // - additional-files before route-files and state-files due to referencing // - additional-files before weight-files since the latter might contain intermodal edge data and the intermodal net depends on the stops and public transport from the additionals // load additional net elements (sources, detectors, ...) if (myOptions.isSet("additional-files")) { if (!load("additional-files")) { return false; } // load shapes with separate handler NLShapeHandler sh("", myNet.getShapeContainer()); if (!ShapeHandler::loadFiles(myOptions.getStringVector("additional-files"), sh)) { return false; } if (myXMLHandler.haveSeenAdditionalSpeedRestrictions()) { myNet.getEdgeControl().setAdditionalRestrictions(); } } // load weights if wished if (myOptions.isSet("weight-files")) { if (!myOptions.isUsableFileList("weight-files")) { return false; } // build and prepare the weights handler std::vector<SAXWeightsHandler::ToRetrieveDefinition*> retrieverDefs; // travel time, first (always used) EdgeFloatTimeLineRetriever_EdgeTravelTime ttRetriever(myNet); retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition("traveltime", true, ttRetriever)); // the measure to use, then EdgeFloatTimeLineRetriever_EdgeEffort eRetriever(myNet); std::string measure = myOptions.getString("weight-attribute"); if (!myOptions.isDefault("weight-attribute")) { if (measure == "CO" || measure == "CO2" || measure == "HC" || measure == "PMx" || measure == "NOx" || measure == "fuel" || measure == "electricity") { measure += "_perVeh"; } retrieverDefs.push_back(new SAXWeightsHandler::ToRetrieveDefinition(measure, true, eRetriever)); } // set up handler SAXWeightsHandler handler(retrieverDefs, ""); // start parsing; for each file in the list std::vector<std::string> files = myOptions.getStringVector("weight-files"); for (std::vector<std::string>::iterator i = files.begin(); i != files.end(); ++i) { // report about loading when wished WRITE_MESSAGE("Loading weights from '" + *i + "'..."); // parse the file if (!XMLSubSys::runParser(handler, *i)) { return false; } } } // load the previous state if wished if (myOptions.isSet("load-state")) { long before = SysUtils::getCurrentMillis(); const std::string& f = myOptions.getString("load-state"); PROGRESS_BEGIN_MESSAGE("Loading state from '" + f + "'"); MSStateHandler h(f, string2time(myOptions.getString("load-state.offset"))); XMLSubSys::runParser(h, f); if (myOptions.isDefault("begin")) { myOptions.set("begin", time2string(h.getTime())); if (TraCIServer::getInstance() != 0) { TraCIServer::getInstance()->setTargetTime(h.getTime()); } } if (MsgHandler::getErrorInstance()->wasInformed()) { return false; } if (h.getTime() != string2time(myOptions.getString("begin"))) { WRITE_WARNING("State was written at a different time " + time2string(h.getTime()) + " than the begin time " + myOptions.getString("begin") + "!"); } PROGRESS_TIME_MESSAGE(before); } // load routes if (myOptions.isSet("route-files") && string2time(myOptions.getString("route-steps")) <= 0) { if (!load("route-files")) { return false; } } // optionally switch off traffic lights if (myOptions.getBool("tls.all-off")) { myNet.getTLSControl().switchOffAll(); } WRITE_MESSAGE("Loading done."); return true; }