mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add breaks
This commit is contained in:
parent
543d1c2ace
commit
4e83871984
16 changed files with 871 additions and 14 deletions
|
|
@ -0,0 +1,39 @@
|
|||
package jsprit.core.algorithm.ruin;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Break;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.BreakActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 04/08/15.
|
||||
*/
|
||||
public class RuinBreakTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
Break aBreak = Break.Builder.newInstance("break").build();
|
||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc"))
|
||||
.setBreak(aBreak).build();
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(v).setJobActivityFactory(vrp.getJobActivityFactory()).addService(aBreak).build();
|
||||
TourActivity tourActivity = route.getActivities().get(0);
|
||||
System.out.println(tourActivity);
|
||||
Assert.assertTrue(tourActivity instanceof BreakActivity);
|
||||
RuinBreaks ruinBreaks = new RuinBreaks();
|
||||
List<Job> unassigned = new ArrayList<Job>();
|
||||
ruinBreaks.ruinEnds(Arrays.asList(route),unassigned);
|
||||
Assert.assertEquals(1,unassigned.size());
|
||||
Assert.assertEquals(aBreak,unassigned.get(0));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.solution.route.activity;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.job.Break;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class BreakActivityTest {
|
||||
|
||||
private Break service;
|
||||
|
||||
private BreakActivity serviceActivity;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
service = (Break) Break.Builder.newInstance("service")
|
||||
.setTimeWindow(TimeWindow.newInstance(1., 2.)).setServiceTime(3).build();
|
||||
serviceActivity = BreakActivity.newInstance(service);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallingCapacity_itShouldReturnCorrectCapacity(){
|
||||
assertEquals(0,serviceActivity.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasVariableLocationShouldBeTrue(){
|
||||
Break aBreak = (Break) serviceActivity.getJob();
|
||||
assertTrue(aBreak.hasVariableLocation());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithEarliestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(1.,serviceActivity.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenStartIsIniWithLatestStart_itShouldBeSetCorrectly(){
|
||||
assertEquals(2.,serviceActivity.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingArrTime_itShouldBeSetCorrectly(){
|
||||
serviceActivity.setArrTime(4.0);
|
||||
assertEquals(4.,serviceActivity.getArrTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingEndTime_itShouldBeSetCorrectly(){
|
||||
serviceActivity.setEndTime(5.0);
|
||||
assertEquals(5.,serviceActivity.getEndTime(),0.01);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenCopyingStart_itShouldBeDoneCorrectly(){
|
||||
BreakActivity copy = (BreakActivity) serviceActivity.duplicate();
|
||||
assertEquals(1.,copy.getTheoreticalEarliestOperationStartTime(),0.01);
|
||||
assertEquals(2.,copy.getTheoreticalLatestOperationStartTime(),0.01);
|
||||
assertTrue(copy!=serviceActivity);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenTwoDeliveriesHaveTheSameUnderlyingJob_theyAreEqual(){
|
||||
Service s1 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build();
|
||||
Service s2 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
ServiceActivity d1 = ServiceActivity.newInstance(s1);
|
||||
ServiceActivity d2 = ServiceActivity.newInstance(s2);
|
||||
|
||||
assertTrue(d1.equals(d2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenTwoDeliveriesHaveTheDifferentUnderlyingJob_theyAreNotEqual(){
|
||||
Service s1 = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).build();
|
||||
Service s2 = Service.Builder.newInstance("s1").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
ServiceActivity d1 = ServiceActivity.newInstance(s1);
|
||||
ServiceActivity d2 = ServiceActivity.newInstance(s2);
|
||||
|
||||
assertFalse(d1.equals(d2));
|
||||
}
|
||||
}
|
||||
|
|
@ -20,6 +20,8 @@ package jsprit.core.problem.vehicle;
|
|||
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.job.Break;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
|
@ -220,6 +222,21 @@ public class VehicleImplTest {
|
|||
.addSkill("drill").build();
|
||||
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingDriverBreak_itShouldBeAddedCorrectly(){
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Break aBreak = (Break) Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start"))
|
||||
.setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.setBreak(aBreak).build();
|
||||
assertNotNull(v.getBreak());
|
||||
assertEquals(100.,v.getBreak().getTimeWindow().getStart(),0.1);
|
||||
assertEquals(200.,v.getBreak().getTimeWindow().getEnd(),0.1);
|
||||
assertEquals(30.,v.getBreak().getServiceDuration(),0.1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue