mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add copyright
This commit is contained in:
parent
05dc00814e
commit
a3d8a9b484
8 changed files with 147 additions and 93 deletions
|
|
@ -1,93 +0,0 @@
|
|||
package analysis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import util.Solutions;
|
||||
import algorithms.VehicleRoutingAlgorithms;
|
||||
import basics.VehicleRoutingAlgorithm;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.VehicleRoutingProblemSolution;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.Priority;
|
||||
|
||||
public class Benchmarker {
|
||||
|
||||
static class Problem {
|
||||
public final String name;
|
||||
public final VehicleRoutingProblem vrp;
|
||||
public final Double bestKnown;
|
||||
public Problem(String name, VehicleRoutingProblem vrp, Double bestKnown) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.vrp = vrp;
|
||||
this.bestKnown = bestKnown;
|
||||
}
|
||||
}
|
||||
|
||||
static class Result {
|
||||
public final double result;
|
||||
public final double time;
|
||||
public final Problem problem;
|
||||
public Double delta = null;
|
||||
public Result(Problem p, double result, double time) {
|
||||
super();
|
||||
this.result = result;
|
||||
this.time = time;
|
||||
this.problem = p;
|
||||
}
|
||||
void setBestKnownDelta(double delta){
|
||||
this.delta = delta;
|
||||
}
|
||||
}
|
||||
|
||||
private String algorithmConfig;
|
||||
|
||||
private List<Problem> problems = new ArrayList<Problem>();
|
||||
|
||||
public Benchmarker(String algorithmConfig) {
|
||||
super();
|
||||
this.algorithmConfig = algorithmConfig;
|
||||
}
|
||||
|
||||
public void addProblem(String name, VehicleRoutingProblem problem){
|
||||
problems.add(new Problem(name,problem,null));
|
||||
}
|
||||
|
||||
public void addProblem(String name, VehicleRoutingProblem problem, double bestKnown){
|
||||
problems.add(new Problem(name,problem,bestKnown));
|
||||
}
|
||||
|
||||
public void run(){
|
||||
List<Result> results = new ArrayList<Benchmarker.Result>();
|
||||
for(Problem p : problems){
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(p.vrp, algorithmConfig);
|
||||
StopWatch stopwatch = new StopWatch();
|
||||
vra.getAlgorithmListeners().addListener(stopwatch,Priority.HIGH);
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
VehicleRoutingProblemSolution best = Solutions.getBest(solutions);
|
||||
Result result = new Result(p,best.getCost(),stopwatch.getCompTimeInSeconds());
|
||||
if(p.bestKnown != null) result.setBestKnownDelta((best.getCost()/p.bestKnown-1));
|
||||
results.add(result);
|
||||
}
|
||||
print(results);
|
||||
}
|
||||
|
||||
private void print(List<Result> results) {
|
||||
System.out.println("instance,time [in sec],result,delta [in percent to bestKnown]");
|
||||
double sumTime=0.0;
|
||||
double sumResult=0.0;
|
||||
for(Result r : results){
|
||||
sumTime+=r.time;
|
||||
sumResult+=r.result;
|
||||
System.out.println("[instance="+r.problem.name+"][time="+round(r.time,2)+"][result="+round(r.result,2)+"][delta="+round(r.delta,3)+"]");
|
||||
}
|
||||
System.out.println("[avgTime="+round(sumTime/(double)results.size(),2)+"][avgResult="+round(sumResult/(double)results.size(),2)+"]");
|
||||
}
|
||||
|
||||
private double round(Double delta, int i) {
|
||||
long roundedVal = Math.round(delta*Math.pow(10, i));
|
||||
return (double)roundedVal/(double)(Math.pow(10, i));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,3 +1,24 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package analysis;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,24 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,24 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
|
||||
package util;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue