diff --git a/jsprit-core/src/main/java/algorithms/JobObserver.java b/jsprit-core/src/main/java/algorithms/JobObserver.java deleted file mode 100644 index 0643bb36..00000000 --- a/jsprit-core/src/main/java/algorithms/JobObserver.java +++ /dev/null @@ -1,156 +0,0 @@ -/******************************************************************************* - * 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 algorithms; - - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; - -import algorithms.RouteStates.ActivityState; -import basics.algo.AlgorithmEndsListener; -import basics.algo.JobInsertedListener; -import basics.route.TourActivity; -import basics.route.VehicleRoute; -import basics.route.TourActivity.JobActivity; -import basics.Job; -import basics.Service; -import basics.VehicleRoutingProblem; -import basics.VehicleRoutingProblemSolution; - -class JobObserver implements JobInsertedListener, BeforeJobInsertionListener, AlgorithmEndsListener{ - - private static class Info { - double depTime; - double tourSize; - double insertionIndex; - double error; - public Info(double depTime, double tourSize, double insertionIndex, - double error) { - super(); - this.depTime = depTime; - this.tourSize = tourSize; - this.insertionIndex = insertionIndex; - this.error = error; - } - - } - - private String locationId = "70"; - - private double routeCostBefore; - private double estimatedMC; - private boolean beforeFirst = false; - - private RouteStates actStates; - - public void setActivityStates(RouteStates actStates){ - this.actStates = actStates; - } - - public ActivityState state(TourActivity act){ - return actStates.getState(act); - } - - - Collection infos = new ArrayList(); - - @Override - public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) { - if(job2insert instanceof Service){ - if(((Service) job2insert).getLocationId().equals(locationId)){ - double actualMC = inRoute.getCost()-routeCostBefore; - TourActivity act = getAct(job2insert,inRoute); - double error = (estimatedMC-actualMC); - int tourSize = inRoute.getTourActivities().getActivities().size(); - int insertionIndex = getIndexOf(job2insert, inRoute); -// infos.add(new Info()) - double depTime = state(act).getEarliestOperationStart()+act.getOperationTime(); - infos.add(new Info(depTime,tourSize,insertionIndex,error)); -// System.out.println("[id=1][tourSize="+tourSize+"][index="+insertionIndex+ -// "][earliestDeparture="+depTime+ -// "][tourCostBefore="+routeCostBefore+"][routeCostAfter="+insertedIn.getCost()+"]" + -// "[estimated="+Math.round(estimatedMC)+"][actual="+Math.round(actualMC)+"][error(abs)="+error + -// "][errorPerNextCustomer="+ (error/(double)(tourSize-insertionIndex)) + "]"); - routeCostBefore = 0.0; - estimatedMC = 0.0; - if(!beforeFirst) throw new IllegalStateException("ähhh"); - beforeFirst = false; - } - } - } - - private TourActivity getAct(Job job2insert, VehicleRoute insertedIn) { - for(TourActivity act : insertedIn.getTourActivities().getActivities()){ - if(act instanceof JobActivity){ - if(((JobActivity) act).getJob().getId().equals(job2insert.getId())){ - return act; - } - } - } - return null; - } - - private int getIndexOf(Job job2insert, VehicleRoute insertedIn) { - int index=0; - for(TourActivity act : insertedIn.getTourActivities().getActivities()){ - if(act instanceof JobActivity){ - if(((JobActivity) act).getJob().getId().equals(job2insert.getId())){ - return index; - } - } - index++; - } - return -1; - } - - @Override - public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) { - if(job instanceof Service){ - if(((Service) job).getLocationId().equals(locationId)){ -// System.out.println("[id=1][tourSize="+route.getTour().getActivities().size()+"][tourCost="+route.getCost()+"]" + -// "[estimatedMarginalInsertionCost="+data.getInsertionCost()+"]"); - routeCostBefore = route.getCost(); - estimatedMC = data.getInsertionCost(); - beforeFirst = true; - } - } - } - - @Override - public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection solutions) { - try { - BufferedWriter writer = new BufferedWriter(new FileWriter("output/errorAna.txt")); - for(Info info : infos){ - writer.write(new StringBuilder().append(info.depTime).append(";").append(info.tourSize).append(";").append(info.insertionIndex).append(";") - .append(info.error).append("\n").toString()); - } - writer.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - -} diff --git a/jsprit-core/src/main/java/algorithms/RouteStates.java b/jsprit-core/src/main/java/algorithms/RouteStates.java deleted file mode 100644 index 19c770c7..00000000 --- a/jsprit-core/src/main/java/algorithms/RouteStates.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * 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 algorithms; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.Logger; - -import basics.Job; -import basics.Service; -import basics.VehicleRoutingProblem; -import basics.VehicleRoutingProblemSolution; -import basics.algo.AlgorithmEndsListener; -import basics.algo.IterationEndsListener; -import basics.algo.IterationStartsListener; -import basics.route.ServiceActivity; -import basics.route.TourActivity; -import basics.route.VehicleRoute; - -class RouteStates implements IterationStartsListener{ - - Logger log = Logger.getLogger(RouteStates.class); - - static class RouteState { - private double costs; - private int load; - private VehicleRoute route; - public RouteState(VehicleRoute route) { - super(); - this.route = route; - } - /** - * @return the costs - */ - public double getCosts() { - return costs; - } - /** - * @param costs the costs to set - */ - public void setCosts(double costs) { - this.costs = costs; - } - /** - * @return the load - */ - public int getLoad() { - return load; - } - /** - * @param load the load to set - */ - public void setLoad(int load) { - this.load = load; - } - - } - - static class ActivityState { - private double earliestOperationStart; - private double latestOperationStart; - private double currentLoad; - private double currentCost; - private TourActivity act; - - public ActivityState(TourActivity activity){ - this.earliestOperationStart=activity.getTheoreticalEarliestOperationStartTime(); - this.latestOperationStart=activity.getTheoreticalLatestOperationStartTime(); - this.act = activity; - } - - @Override - public String toString() { - return "[earliestStart="+earliestOperationStart+"][latestStart="+ - latestOperationStart+"][currLoad="+currentLoad+"][currCost="+currentCost+"]"; - } - - public double getEarliestOperationStart() { - return earliestOperationStart; - } - - void setEarliestOperationStart(double earliestOperationStart) { - this.earliestOperationStart = earliestOperationStart; - } - - public double getLatestOperationStart() { - return latestOperationStart; - } - - void setLatestOperationStart(double latestOperationStart) { - this.latestOperationStart = latestOperationStart; - } - - public double getCurrentLoad() { - return currentLoad; - } - - void setCurrentLoad(double currentLoad) { - this.currentLoad = currentLoad; - } - - public double getCurrentCost() { - return currentCost; - } - - void setCurrentCost(double currentCost) { - this.currentCost = currentCost; - } - - public void reset() { - earliestOperationStart = act.getTheoreticalEarliestOperationStartTime(); - latestOperationStart = act.getTheoreticalLatestOperationStartTime() ; - currentLoad = 0.0; - currentCost = 0.0; - } - } - - - private Map activityStates; - - private Map tourActivities; - - private Map routeStates; - - public RouteStates() { - activityStates = new HashMap(); - tourActivities = new HashMap(); - routeStates = new HashMap(); - } - - ActivityState getState(TourActivity act){ - if(!activityStates.containsKey(act)) return null; - return activityStates.get(act); - } - - public void clearStates(){ - activityStates.clear(); - } - - public Map getActivityStates() { - return activityStates; - } - - TourActivity getActivity(Service service, boolean resetState){ - TourActivity tourActivity = tourActivities.get(service); - getState(tourActivity).reset(); - return tourActivity; - } - - public void resetRouteStates(){ - routeStates.clear(); - } - - public RouteState getRouteState(VehicleRoute route){ - RouteState routeState = routeStates.get(route); - if(routeState == null){ - routeState = new RouteState(route); - putRouteState(route, routeState); - } - return routeState; - } - - private void putRouteState(VehicleRoute route, RouteState routeState){ - routeStates.put(route, routeState); - } - - void initialiseStateOfJobs(Collection jobs){ - for(Job job : jobs){ - if(job instanceof Service){ - ServiceActivity service = ServiceActivity.newInstance((Service)job); - ActivityState state = new ActivityState(service); - tourActivities.put((Service) job, service); - activityStates.put(service, state); - } - else{ - throw new IllegalStateException(); - } - } - } - - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - resetRouteStates(); - } - - - -}