@zfunction/genetics-js
Version:
Genetic and evolutionary algorithms framework for the web
108 lines • 4.18 kB
JavaScript
;
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var child_process_1 = __importDefault(require("child_process"));
var fs_1 = __importDefault(require("fs"));
/*
SUMO options:
-n, --net-file FILE Load road network description from FILE
-r, --route-files FILE Load routes descriptions from FILE(s)
-a, --additional-files FILE Load further descriptions from FILE(s)
*/
var COMMAND_NAME = "sumo";
var child;
function parseSumoAggegatedOutputData(sumoOutput) {
var get = function (r) {
var _a;
return Number((_a = sumoOutput.match(r)) === null || _a === void 0 ? void 0 : _a[1]);
};
return {
performance: {
duration: get(/Duration: ([0-9]*)ms/i),
realTimeFactor: get(/Real time factor: ([0-9.]*)/i),
},
vehicles: {
inserted: get(/Inserted: ([0-9]*)/i),
loaded: get(/Loaded: ([0-9]*)/i),
running: get(/Running: ([0-9]*)/i),
waiting: get(/Waiting: ([0-9]*)/i),
},
teleports: {
jam: get(/Jam: ([0-9]*)/i),
wrongLane: get(/Wrong Lane: ([0-9]*)/i),
yield: get(/Yield: ([0-9]*)/i),
total: get(/Teleports: ([0-9]*)/i),
},
statistics: {
departDelay: get(/DepartDelay: ([.0-9]*)/i),
duration: get(/Duration: ([0-9]*\.[0-9]*)/i),
routeLength: get(/RouteLength: ([.0-9]*)/i),
speed: get(/Speed: ([.0-9]*)/i),
timeLoss: get(/TimeLoss: ([.0-9]*)/i),
waitingTime: get(/WaitingTime: ([.0-9]*)/i),
},
};
}
var util_1 = require("util");
function ins(x, colors) {
if (colors === void 0) { colors = true; }
return util_1.inspect(x, { depth: 30, colors: colors, maxArrayLength: 30 });
}
exports.ins = ins;
function executeSumo(sumoOptions) {
checkFilesExists(sumoOptions.files.routes);
var command = (sumoOptions.command_name ? sumoOptions.command_name : COMMAND_NAME) + " ";
command += sumoOptions.flags.join(" ") + " ";
command += "--net-file " + sumoOptions.files.network + " ";
command += "--additional-files " + sumoOptions.files.routes.map(function (elem) { return '"' + elem + '"'; }).join(",");
if (sumoOptions.files.additional) {
command += " --additional-files " + sumoOptions.files.additional.join(",");
}
console.log("Executing '" + command + "'");
child = child_process_1.default.spawnSync(command, {
cwd: process.cwd(),
env: process.env,
stdio: "pipe",
encoding: "utf-8",
shell: true,
killSignal: "SIGINT",
});
if (child.status !== 0) {
process.exit(1);
}
return parseSumoAggegatedOutputData(child.output.join());
}
exports.executeSumo = executeSumo;
function checkFilesExists(path) {
var e_1, _a;
try {
for (var path_1 = __values(path), path_1_1 = path_1.next(); !path_1_1.done; path_1_1 = path_1.next()) {
var x = path_1_1.value;
// console.log("Checking " + x);
if (!fs_1.default.existsSync(x)) {
throw "File doesnt exist: " + x;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (path_1_1 && !path_1_1.done && (_a = path_1.return)) _a.call(path_1);
}
finally { if (e_1) throw e_1.error; }
}
}
//# sourceMappingURL=executor.js.map