mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
vis
This commit is contained in:
parent
b702c8015b
commit
020ee56366
2 changed files with 19 additions and 54 deletions
|
|
@ -41,10 +41,12 @@ import org.graphstream.graph.implementations.MultiGraph;
|
||||||
import org.graphstream.stream.file.FileSinkDGS;
|
import org.graphstream.stream.file.FileSinkDGS;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.zip.GZIPOutputStream;
|
||||||
|
|
||||||
|
|
||||||
public class AlgorithmEventRecorder implements RuinListener, IterationStartsListener, InsertionStartsListener, BeforeJobInsertionListener, InsertionEndsListener, AlgorithmEndsListener {
|
public class AlgorithmEventRecorder implements RuinListener, IterationStartsListener, InsertionStartsListener, BeforeJobInsertionListener, InsertionEndsListener, AlgorithmEndsListener {
|
||||||
|
|
@ -58,10 +60,6 @@ public class AlgorithmEventRecorder implements RuinListener, IterationStartsList
|
||||||
rec.finish();
|
rec.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum RecordPolicy {
|
|
||||||
RECORD_AND_WRITE
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final int BEFORE_RUIN_RENDER_SOLUTION = 2;
|
public static final int BEFORE_RUIN_RENDER_SOLUTION = 2;
|
||||||
|
|
||||||
public static final int RUIN = 0;
|
public static final int RUIN = 0;
|
||||||
|
|
@ -78,6 +76,10 @@ public class AlgorithmEventRecorder implements RuinListener, IterationStartsList
|
||||||
|
|
||||||
private FileSinkDGS fileSink;
|
private FileSinkDGS fileSink;
|
||||||
|
|
||||||
|
private FileOutputStream fos;
|
||||||
|
|
||||||
|
private GZIPOutputStream gzipOs;
|
||||||
|
|
||||||
private int start_recording_at = 0;
|
private int start_recording_at = 0;
|
||||||
|
|
||||||
private int end_recording_at = Integer.MAX_VALUE;
|
private int end_recording_at = Integer.MAX_VALUE;
|
||||||
|
|
@ -86,13 +88,19 @@ public class AlgorithmEventRecorder implements RuinListener, IterationStartsList
|
||||||
|
|
||||||
private VehicleRoutingProblem vrp;
|
private VehicleRoutingProblem vrp;
|
||||||
|
|
||||||
public AlgorithmEventRecorder(VehicleRoutingProblem vrp, File outfile) {
|
public AlgorithmEventRecorder(VehicleRoutingProblem vrp, File dgsFile) {
|
||||||
this.vrp = vrp;
|
this.vrp = vrp;
|
||||||
graph = new MultiGraph("g");
|
graph = new MultiGraph("g");
|
||||||
try {
|
try {
|
||||||
writer = new FileWriter(outfile);
|
fos = new FileOutputStream(dgsFile);
|
||||||
fileSink = new FileSinkDGS();
|
fileSink = new FileSinkDGS();
|
||||||
fileSink.begin(writer);
|
if(dgsFile.getName().endsWith("gz")){
|
||||||
|
gzipOs = new GZIPOutputStream(fos);
|
||||||
|
fileSink.begin(gzipOs);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
fileSink.begin(fos);
|
||||||
|
}
|
||||||
graph.addSink(fileSink);
|
graph.addSink(fileSink);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
@ -100,9 +108,9 @@ public class AlgorithmEventRecorder implements RuinListener, IterationStartsList
|
||||||
initialiseGraph(vrp);
|
initialiseGraph(vrp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlgorithmEventRecorder(VehicleRoutingProblem vrp, File outfile, boolean renderShipments) {
|
public AlgorithmEventRecorder(VehicleRoutingProblem vrp, File dgsFile, boolean renderShipments) {
|
||||||
this.renderShipments = renderShipments;
|
this.renderShipments = renderShipments;
|
||||||
new AlgorithmEventRecorder(vrp,outfile);
|
new AlgorithmEventRecorder(vrp,dgsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRecordingRange(int startIteration, int endIteration){
|
public void setRecordingRange(int startIteration, int endIteration){
|
||||||
|
|
@ -110,23 +118,6 @@ public class AlgorithmEventRecorder implements RuinListener, IterationStartsList
|
||||||
this.end_recording_at = endIteration;
|
this.end_recording_at = endIteration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AlgorithmEventRecorder(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution initialSolution, File outfile) {
|
|
||||||
// this.outfile = outfile;
|
|
||||||
// this.vrp = vrp;
|
|
||||||
// graph = new MultiGraph("g");
|
|
||||||
// try {
|
|
||||||
// writer = new FileWriter(outfile);
|
|
||||||
// writeHead();
|
|
||||||
// } catch (IOException e) {
|
|
||||||
// e.printStackTrace();
|
|
||||||
// }
|
|
||||||
// initialiseGraph(vrp,initialSolution);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initialiseGraph(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution initialSolution) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ruinStarts(Collection<VehicleRoute> routes) {
|
public void ruinStarts(Collection<VehicleRoute> routes) {
|
||||||
if(!record()) return;
|
if(!record()) return;
|
||||||
|
|
@ -292,7 +283,8 @@ public class AlgorithmEventRecorder implements RuinListener, IterationStartsList
|
||||||
private void finish() {
|
private void finish() {
|
||||||
try {
|
try {
|
||||||
fileSink.end();
|
fileSink.end();
|
||||||
writer.close();
|
fos.close();
|
||||||
|
if(gzipOs != null) gzipOs.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
package jsprit.analysis.toolbox;
|
|
||||||
|
|
||||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
|
||||||
import jsprit.core.algorithm.box.GreedySchrimpfFactory;
|
|
||||||
import jsprit.core.problem.VehicleRoutingProblem;
|
|
||||||
import jsprit.core.problem.io.VrpXMLReader;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by stefan on 14.11.14.
|
|
||||||
*/
|
|
||||||
public class AnotherGraphTest {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
|
||||||
new VrpXMLReader(vrpBuilder).read("/Users/stefan/Documents/git-repositories/jsprit/jsprit-examples/input/cordeau01.xml");
|
|
||||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
|
||||||
|
|
||||||
// GraphStreamEventWriter eventWriter = new GraphStreamEventWriter(new File("output/events.txt"));
|
|
||||||
VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrp);
|
|
||||||
// vra.addListener(eventWriter);
|
|
||||||
|
|
||||||
vra.searchSolutions();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue