run it my dudes
This commit is contained in:
parent
3e0beafa55
commit
a3a67035d8
@ -6,5 +6,6 @@
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="include/commons-csv-1.7/commons-csv-1.7.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
20
ampl/ampl_model.dat
Normal file
20
ampl/ampl_model.dat
Normal file
@ -0,0 +1,20 @@
|
||||
set EVAC := Troy Brunswick ;
|
||||
set DEST := Albany Guilderland EastGreenbush Schenectady ;
|
||||
param: EDGES : edgecapacity :=
|
||||
Troy Brunswick 250.000000
|
||||
Troy Guilderland 200.000000
|
||||
Troy Albany 500.000000
|
||||
Troy EastGreenbush 100.000000
|
||||
Brunswick EastGreenbush 100.000000
|
||||
Guilderland Schenectady 100.000000
|
||||
;
|
||||
param population :=
|
||||
Troy 700
|
||||
Brunswick 300
|
||||
;
|
||||
param capacity :=
|
||||
Albany 3000
|
||||
Guilderland 300
|
||||
EastGreenbush 500
|
||||
Schenectady 400
|
||||
;
|
7
ampl/ampl_solve.run
Normal file
7
ampl/ampl_solve.run
Normal file
@ -0,0 +1,7 @@
|
||||
model model.mdl;
|
||||
|
||||
data ampl_model.dat;
|
||||
|
||||
solve;
|
||||
|
||||
display Flow;
|
6
data/flows.csv
Normal file
6
data/flows.csv
Normal file
@ -0,0 +1,6 @@
|
||||
Brunswick,EastGreenbush,300
|
||||
Guilderland,Schenectady,0
|
||||
Troy,Albany,200
|
||||
Troy,Brunswick,0
|
||||
Troy,EastGreenbush,200
|
||||
Troy,Guilderland,300
|
|
31
node/run.js
31
node/run.js
@ -1,4 +1,5 @@
|
||||
const child_process = require('child_process');
|
||||
const fs = require('fs');
|
||||
|
||||
async function run_process(command, args, cwd) {
|
||||
let process = child_process.spawn(command, args, { cwd: cwd });
|
||||
@ -16,13 +17,16 @@ async function run_process(command, args, cwd) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
process.on('close', (code, signal) => {
|
||||
if (code != 0) {
|
||||
reject('exit code: ' + code);
|
||||
}
|
||||
console.log('code', code, 'signal', signal);
|
||||
console.log('stdout');
|
||||
console.log(stdout);
|
||||
|
||||
console.log('stderr');
|
||||
console.log(stderr);
|
||||
resolve();
|
||||
resolve(stdout);
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -33,12 +37,33 @@ async function run() {
|
||||
// launch java (read input data)
|
||||
|
||||
cwd = "/home/elipzer/eclipse-workspace/EvacuationPlanner";
|
||||
await run_process("java", [ "-classpath", "/home/elipzer/eclipse-workspace/EvacuationPlanner/bin", "evac.KmlTest" ], cwd);
|
||||
try {
|
||||
await run_process("java", [
|
||||
"-classpath",
|
||||
"/home/elipzer/eclipse-workspace/EvacuationPlanner/bin"
|
||||
+ ":/home/elipzer/eclipse-workspace/EvacuationPlanner/include/commons-csv-1.7/commons-csv-1.7.jar",
|
||||
"evac.AmplPrepMain" ], cwd);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
// launch ampl (calculate flows)
|
||||
|
||||
cwd = "/home/elipzer/eclipse-workspace/EvacuationPlanner/ampl";
|
||||
await run_process("ampl", [ "solve.run" ], cwd);
|
||||
try {
|
||||
let output = await run_process("ampl", [ "ampl_solve.run" ], cwd);
|
||||
let lines = output.split('\n');
|
||||
let semicolon = lines.indexOf(';');
|
||||
let flows = lines.slice(3, semicolon);
|
||||
let flowsCsv = flows.map(line => {
|
||||
return line.replace(/\s+/g, ',');
|
||||
}).join('\n');
|
||||
fs.writeFileSync('../data/flows.csv', flowsCsv);
|
||||
console.log('output (flows.csv):');
|
||||
console.log(flowsCsv);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
|
||||
// launch java (generate kml)
|
||||
|
||||
|
44
src/evac/AmplGenerator.java
Normal file
44
src/evac/AmplGenerator.java
Normal file
@ -0,0 +1,44 @@
|
||||
package evac;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AmplGenerator {
|
||||
public static String createData(InputModel model, List<Node> evac, List<Node> dest) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append("set EVAC := ");
|
||||
for (Node n : evac) {
|
||||
builder.append(n.name);
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append(";\n");
|
||||
|
||||
builder.append("set DEST := ");
|
||||
for (Node n : dest) {
|
||||
builder.append(n.name);
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append(";\n");
|
||||
|
||||
builder.append("param: EDGES : edgecapacity :=\n");
|
||||
for (Edge edge : model.edges) {
|
||||
builder.append(String.format(" %s %s %f\n", edge.src.name, edge.dst.name, edge.capacity));
|
||||
}
|
||||
builder.append(";\n");
|
||||
|
||||
builder.append("param population :=\n");
|
||||
for (Node n : evac) {
|
||||
builder.append(String.format(" %s %d\n", n.name, n.population));
|
||||
}
|
||||
builder.append(";\n");
|
||||
|
||||
builder.append("param capacity :=\n");
|
||||
for (Node n : dest) {
|
||||
builder.append(String.format(" %s %d\n", n.name, n.capacity - n.population));
|
||||
}
|
||||
builder.append(";\n");
|
||||
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
78
src/evac/AmplPrepMain.java
Normal file
78
src/evac/AmplPrepMain.java
Normal file
@ -0,0 +1,78 @@
|
||||
package evac;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class AmplPrepMain {
|
||||
public static void main(String[] args) {
|
||||
// Hardcoded for testing
|
||||
String arg1 = "models/troy_model/main.csv";
|
||||
String arg2 = "models/troy_model/nodes.csv";
|
||||
String arg3 = "models/troy_model/edges.csv";
|
||||
String arg4 = "models/troy_model/hurricanes.csv";
|
||||
|
||||
InputModel inputModel = new InputModel();
|
||||
|
||||
Translator translator = new Translator(inputModel, arg1, arg2, arg3, arg4);
|
||||
|
||||
if (!translator.translateMain()) {
|
||||
System.out.println("Error while translating main");
|
||||
return;
|
||||
}
|
||||
System.out.println("Finished translating main");
|
||||
|
||||
if (!translator.translateNodes()) {
|
||||
System.out.println("Error while translating nodes");
|
||||
return;
|
||||
}
|
||||
System.out.println("Finished translating nodes");
|
||||
|
||||
if (!translator.translateEdges()) {
|
||||
System.out.println("Error while translating edges");
|
||||
return;
|
||||
}
|
||||
System.out.println("Finished translating edges");
|
||||
|
||||
if (!translator.translateHurricanes()) {
|
||||
System.out.println("Error while translating hurricanes");
|
||||
}
|
||||
System.out.println("Finished translating hurricanes");
|
||||
|
||||
List<Node> evac = new ArrayList<>();
|
||||
evac.add(inputModel.nodes.get("Troy")); // troy
|
||||
evac.add(inputModel.nodes.get("Brunswick")); // brunswick
|
||||
|
||||
List<Node> dest = new ArrayList<>();
|
||||
dest.add(inputModel.nodes.get("Albany"));
|
||||
dest.add(inputModel.nodes.get("Guilderland"));
|
||||
dest.add(inputModel.nodes.get("EastGreenbush"));
|
||||
dest.add(inputModel.nodes.get("Schenectady"));
|
||||
|
||||
System.out.println("evac");
|
||||
for (Node node : evac) {
|
||||
System.out.println(" " + node.name);
|
||||
}
|
||||
|
||||
System.out.println("dest");
|
||||
for (Node node : dest) {
|
||||
System.out.println(" " + node.name);
|
||||
}
|
||||
|
||||
String ampl = AmplGenerator.createData(inputModel, evac, dest);
|
||||
|
||||
File amplDataFile = new File("./ampl/ampl_model.dat");
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(amplDataFile))) {
|
||||
writer.write(ampl);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("data output:");
|
||||
System.out.println(ampl);
|
||||
|
||||
}
|
||||
}
|
@ -123,7 +123,7 @@ public class KmlGenerator {
|
||||
builder.append(String.format(" <tr><td>Direction</td><td>%f\u00b0 @ %f mph</td></tr>\n", hurricaneData.velocity.inclination, hurricaneData.velocity.speed));
|
||||
builder.append(String.format(" <tr><td>Wind Speed</td><td>%f mph</td></tr>\n", hurricaneData.wind));
|
||||
//builder.append(String.format(" <tr><td>Wind Gusts</td><td>%f mph</td></tr>\n", hurricaneData.gusts));
|
||||
builder.append(String.format(" <tr><td>Category</td><td>%d</td></tr>\n", hurricaneData.category));
|
||||
builder.append(String.format(" <tr><td>Category</td><td>%f</td></tr>\n", hurricaneData.category));
|
||||
builder.append(" </table>\n");
|
||||
builder.append(" ]]></description>\n");
|
||||
builder.append(" <Point>\n");
|
||||
|
@ -1,6 +1,8 @@
|
||||
package evac;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
|
||||
@ -48,6 +50,30 @@ public class Main {
|
||||
}
|
||||
System.out.println("Finished translating hurricanes");
|
||||
|
||||
List<Node> evac = new ArrayList<>();
|
||||
evac.add(inputModel.nodes.get("Troy")); // troy
|
||||
evac.add(inputModel.nodes.get("Brunswick")); // brunswick
|
||||
|
||||
List<Node> dest = new ArrayList<>();
|
||||
dest.add(inputModel.nodes.get("Albany"));
|
||||
dest.add(inputModel.nodes.get("Guilderland"));
|
||||
dest.add(inputModel.nodes.get("EastGreenbush"));
|
||||
dest.add(inputModel.nodes.get("Schenectady"));
|
||||
|
||||
System.out.println("evac");
|
||||
for (Node node : evac) {
|
||||
System.out.println(node.name);
|
||||
}
|
||||
|
||||
System.out.println("dest");
|
||||
for (Node node : dest) {
|
||||
System.out.println(node.name);
|
||||
}
|
||||
|
||||
|
||||
String ampl = AmplGenerator.createData(inputModel, evac, dest);
|
||||
System.out.println(ampl);
|
||||
|
||||
// Start simulation
|
||||
OutputModel outputModel = NumberCruncher.crunch(inputModel);
|
||||
String kml = KmlGenerator.createKml(outputModel);
|
||||
|
Loading…
Reference in New Issue
Block a user