use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class OperationsCarRouterTest method testRoutingWithSchedulesMatchMode2.
/*
* Using the setup from the previous tests, use trains and schedules to move
* cars. This test creates 1 schedule in match mode with multiple items.
* Cars use final destination to activate schedule
*/
public void testRoutingWithSchedulesMatchMode2() {
TrainManager tmanager = TrainManager.instance();
CarManager cmanager = CarManager.instance();
LocationManager lmanager = LocationManager.instance();
loadLocationsTrainsAndCars();
List<Train> trains = tmanager.getTrainsByNameList();
Assert.assertEquals("confirm number of trains", 7, trains.size());
Car c3 = cmanager.getByRoadAndNumber("BA", "3");
Car c4 = cmanager.getByRoadAndNumber("BB", "4");
Car c5 = cmanager.getByRoadAndNumber("BC", "5");
Car c6 = cmanager.getByRoadAndNumber("BD", "6");
Car c7 = cmanager.getByRoadAndNumber("BA", "7");
Car c8 = cmanager.getByRoadAndNumber("BB", "8");
Car c9 = cmanager.getByRoadAndNumber("BC", "9");
Assert.assertNotNull("confirm car not null", c3);
Assert.assertNotNull("confirm car not null", c4);
Assert.assertNotNull("confirm car not null", c5);
Assert.assertNotNull("confirm car not null", c6);
Assert.assertNotNull("confirm car not null", c7);
Assert.assertNotNull("confirm car not null", c8);
Assert.assertNotNull("confirm car not null", c9);
Location Acton = lmanager.getLocationByName("Acton MA");
Location Bedford = lmanager.getLocationByName("Bedford MA");
Location Clinton = lmanager.getLocationByName("Clinton MA");
Location Danbury = lmanager.getLocationByName("Danbury MA");
Location Essex = lmanager.getLocationByName("Essex MA");
Location Foxboro = lmanager.getLocationByName("Foxboro MA");
Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
Track BS1 = Bedford.getTrackByName("Bedford Siding 1", Track.SPUR);
Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
Track DS1 = Danbury.getTrackByName("Danbury Siding 1", Track.SPUR);
Track DS2 = Danbury.getTrackByName("Danbury Siding 2", Track.SPUR);
Track ES1 = Essex.getTrackByName("Essex Siding 1", Track.SPUR);
//Track ES2 = Essex.getTrackByName("Essex Siding 2", Track.SIDING);
Track FS1 = Foxboro.getTrackByName("Foxboro Siding 1", Track.SPUR);
// set the depart track Acton to service by local train only
AS1.setTrainDirections(0);
// create schedules
ScheduleManager scheduleManager = ScheduleManager.instance();
Schedule schA = scheduleManager.newSchedule("Schedule ABC");
ScheduleItem schAItem1 = schA.addItem("Boxcar");
schAItem1.setReceiveLoadName("Cardboard");
schAItem1.setShipLoadName("Metal");
schAItem1.setDestination(Acton);
schAItem1.setDestinationTrack(AS1);
ScheduleItem schAItem2 = schA.addItem("Flat");
//schAItem2.setLoad("Junk");
schAItem2.setShipLoadName("Metal");
schAItem2.setDestination(Danbury);
schAItem2.setDestinationTrack(DS2);
ScheduleItem schAItem3 = schA.addItem("Boxcar");
schAItem3.setReceiveLoadName("Tools");
schAItem3.setShipLoadName("Screws");
schAItem3.setDestination(Bedford);
schAItem3.setDestinationTrack(BS1);
ScheduleItem schAItem4 = schA.addItem("Boxcar");
schAItem4.setReceiveLoadName(CarLoads.instance().getDefaultEmptyName());
schAItem4.setShipLoadName("Bolts");
schAItem4.setDestination(Danbury);
schAItem4.setDestinationTrack(DS1);
ScheduleItem schAItem5 = schA.addItem("Boxcar");
schAItem5.setReceiveLoadName(CarLoads.instance().getDefaultLoadName());
schAItem5.setShipLoadName("Nuts");
schAItem5.setDestination(Foxboro);
schAItem5.setDestinationTrack(FS1);
// Add schedule to tracks
CS1.setScheduleId("");
ES1.setScheduleId(schA.getId());
// set schedule into match mode
ES1.setScheduleMode(Track.MATCH);
// c3 (BA 3) is a Boxcar
c3.setLoadName("Tools");
c3.setFinalDestination(Essex);
// c4 (BB 4) is a Flat
c4.setLoadName(CarLoads.instance().getDefaultEmptyName());
c4.setFinalDestination(Essex);
c4.setFinalDestinationTrack(ES1);
// c5 (BC 5) is a Boxcar
c5.setLoadName("Tools");
c5.setFinalDestination(Essex);
// c6 (BD 6) is a Boxcar
c6.setLoadName(CarLoads.instance().getDefaultEmptyName());
c6.setFinalDestination(Essex);
// c7 (BA 7) is a Boxcar
c7.setLoadName("Cardboard");
c7.setFinalDestination(Essex);
c7.setFinalDestinationTrack(ES1);
// c8 (BB 8) is a Boxcar
c8.setLoadName("Tools");
// serve BB 8 and BC 9 after the other cars
c8.setMoves(20);
// c9 (BC 9) is a Boxcar
c9.setLoadName(CarLoads.instance().getDefaultEmptyName());
c9.setMoves(21);
// place cars
Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c5.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c6.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c7.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c8.setLocation(Danbury, DS1));
Assert.assertEquals("Place car", Track.OKAY, c9.setLocation(Danbury, DS1));
// build train
Train ActonTrain = tmanager.getTrainByName("Acton Local");
ActonTrain.build();
Assert.assertTrue("Acton train built", ActonTrain.isBuilt());
// check car destinations
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Interchange", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Essex MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Interchange", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Essex MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Essex Siding 1", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Acton Interchange", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "Essex MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "Essex MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 7 destination", "Acton MA", c7.getDestinationName());
Assert.assertEquals("Car BA 7 destination track", "Acton Interchange", c7.getDestinationTrackName());
Assert.assertEquals("Car BA 7 final destination", "Essex MA", c7.getFinalDestinationName());
Assert.assertEquals("Car BA 7 final destination track", "Essex Siding 1", c7.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 8 destination", "", c8.getDestinationName());
Assert.assertEquals("Car BB 8 destination track", "", c8.getDestinationTrackName());
Assert.assertEquals("Car BB 8 final destination", "", c8.getFinalDestinationName());
Assert.assertEquals("Car BB 8 final destination track", "", c8.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 9 destination", "", c9.getDestinationName());
Assert.assertEquals("Car BC 9 destination track", "", c9.getDestinationTrackName());
Assert.assertEquals("Car BC 9 final destination", "", c9.getFinalDestinationName());
Assert.assertEquals("Car BC 9 final destination track", "", c9.getFinalDestinationTrackName());
// check car schedule ids
// no track assignment, schedule not tested
Assert.assertEquals("Car BA 3 schedule id", "", c3.getScheduleItemId());
// has track assignment
Assert.assertEquals("Car BB 4 schedule id", schAItem2.getId(), c4.getScheduleItemId());
Assert.assertEquals("Car BC 5 schedule id", "", c5.getScheduleItemId());
Assert.assertEquals("Car BD 6 schedule id", "", c6.getScheduleItemId());
// has track assignment
Assert.assertEquals("Car BA 7 schedule id", schAItem1.getId(), c7.getScheduleItemId());
Assert.assertEquals("Car BB 8 schedule id", "", c8.getScheduleItemId());
Assert.assertEquals("Car BC 9 schedule id", "", c9.getScheduleItemId());
ActonTrain.terminate();
// move the cars to Bedford
Train ActonToBedfordTrain = tmanager.getTrainByName("Acton to Bedford");
ActonToBedfordTrain.build();
Assert.assertTrue("Acton train built", ActonToBedfordTrain.isBuilt());
ActonToBedfordTrain.terminate();
// move the cars to Clinton
Train BedfordToClintonTrain = tmanager.getTrainByName("Bedford to Clinton");
BedfordToClintonTrain.build();
Assert.assertTrue("Bedford train built", BedfordToClintonTrain.isBuilt());
BedfordToClintonTrain.terminate();
// move the cars to Danbury
Train ClintonToDanburyTrain = tmanager.getTrainByName("Clinton to Danbury");
ClintonToDanburyTrain.build();
Assert.assertTrue("Clinton train built", ClintonToDanburyTrain.isBuilt());
ClintonToDanburyTrain.terminate();
// move the cars to Essex (number of moves is 8)
Train DanburyToEssexTrain = tmanager.getTrainByName("Danbury to Essex");
DanburyToEssexTrain.build();
Assert.assertTrue("Danbury train built", DanburyToEssexTrain.isBuilt());
// check car destinations
// BA 3 (Boxcar)
Assert.assertEquals("Car BA 3 destination", "Essex MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Essex Siding 1", c3.getDestinationTrackName());
// new final destination and load for car BA 3
Assert.assertEquals("Car BA 3 final destination", "Bedford MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Bedford Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 3 final load", "Screws", c3.getNextLoadName());
Assert.assertEquals("Car BA 3 schedule id", "", c3.getScheduleItemId());
// BB 4 (Flat)
Assert.assertEquals("Car BB 4 destination", "Essex MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Essex Siding 1", c4.getDestinationTrackName());
// new final destination and load for car BB 4
Assert.assertEquals("Car BB 4 final destination", "Danbury MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Danbury Siding 2", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 final load", "Metal", c4.getNextLoadName());
Assert.assertEquals("Car BB 4 schedule id", "", c4.getScheduleItemId());
// BC 5 (Boxcar)
Assert.assertEquals("Car BC 5 destination", "Essex MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Essex Siding 1", c5.getDestinationTrackName());
// new final destination and load for car BC 5, same as BA 3
Assert.assertEquals("Car BC 5 final destination", "Bedford MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "Bedford Siding 1", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 final load", "Screws", c5.getNextLoadName());
Assert.assertEquals("Car BC 5 schedule id", "", c5.getScheduleItemId());
// BD 6 (Boxcar) note second Boxcar
Assert.assertEquals("Car BD 6 destination", "Essex MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Essex Siding 1", c6.getDestinationTrackName());
// new final destination and load for car BD 6
Assert.assertEquals("Car BD 6 final destination", "Danbury MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "Danbury Siding 1", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 6 final load", "Bolts", c6.getNextLoadName());
Assert.assertEquals("Car BD 6 schedule id", "", c6.getScheduleItemId());
// BA 7 (Boxcar) note 3rd Boxcar
Assert.assertEquals("Car BA 7 destination", "Essex MA", c7.getDestinationName());
Assert.assertEquals("Car BA 7 destination track", "Essex Siding 1", c7.getDestinationTrackName());
// new final destination and load for car BA 7
Assert.assertEquals("Car BA 7 final destination", "Acton MA", c7.getFinalDestinationName());
Assert.assertEquals("Car BA 7 final destination track", "Acton Siding 1", c7.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 7 final load", "Metal", c7.getNextLoadName());
Assert.assertEquals("Car BA 7 schedule id", "", c7.getScheduleItemId());
// BB 8 (Boxcar) at Danbury to be added to train
Assert.assertEquals("Car BB 8 destination", "Essex MA", c8.getDestinationName());
Assert.assertEquals("Car BB 8 destination track", "Essex Siding 1", c8.getDestinationTrackName());
// Should match schedule item 16c3
Assert.assertEquals("Car BB 8 final destination", "Bedford MA", c8.getFinalDestinationName());
Assert.assertEquals("Car BB 8 final destination track", "Bedford Siding 1", c8.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 8 final load", "Screws", c8.getNextLoadName());
Assert.assertEquals("Car BB 8 schedule id", "", c8.getScheduleItemId());
// BB 9 (Boxcar) at Danbury to be added to train
Assert.assertEquals("Car BC 9 destination", "Essex MA", c9.getDestinationName());
Assert.assertEquals("Car BC 9 destination track", "Essex Siding 1", c9.getDestinationTrackName());
// Should match schedule item 16c4
Assert.assertEquals("Car BC 9 final destination", "Danbury MA", c9.getFinalDestinationName());
Assert.assertEquals("Car BC 9 final destination track", "Danbury Siding 1", c9.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 9 final load", "Bolts", c9.getNextLoadName());
Assert.assertEquals("Car BC 9 schedule id", "", c9.getScheduleItemId());
// test reset, car final destinations should revert.
DanburyToEssexTrain.reset();
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Essex MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 3 next load", "", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Essex MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Essex Siding 1", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 destination", "", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "Essex MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 destination", "", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "Essex MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 7 destination", "", c7.getDestinationName());
Assert.assertEquals("Car BA 7 destination track", "", c7.getDestinationTrackName());
Assert.assertEquals("Car BA 7 final destination", "Essex MA", c7.getFinalDestinationName());
Assert.assertEquals("Car BA 7 final destination track", "Essex Siding 1", c7.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 8 destination", "", c8.getDestinationName());
Assert.assertEquals("Car BB 8 destination track", "", c8.getDestinationTrackName());
Assert.assertEquals("Car BB 8 final destination", "", c8.getFinalDestinationName());
Assert.assertEquals("Car BB 8 final destination track", "", c8.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 9 destination", "", c9.getDestinationName());
Assert.assertEquals("Car BC 9 destination track", "", c9.getDestinationTrackName());
Assert.assertEquals("Car BC 9 final destination", "", c9.getFinalDestinationName());
Assert.assertEquals("Car BC 9 final destination track", "", c9.getFinalDestinationTrackName());
// // try again
// DanburyToEssexTrain.build();
// Assert.assertTrue("Bedford train built", DanburyToEssexTrain.isBuilt());
//
// // check car destinations
// // BA 3 (Boxcar) this car's load and final destination is now different
// Assert.assertEquals("Car BA 3 destination","Essex MA", c3.getDestinationName());
// Assert.assertEquals("Car BA 3 destination track","Essex Siding 1", c3.getDestinationTrackName());
// // new final destination and load for car BA 3
// Assert.assertEquals("Car BA 3 final destination","Acton MA", c3.getFinalDestinationName());
// Assert.assertEquals("Car BA 3 final destination track","Acton Siding 1", c3.getFinalDestinationTrackName());
// Assert.assertEquals("Car BA 3 next load","Metal", c3.getNextLoadName());
// Assert.assertEquals("Car BA 3 schedule id", "", c3.getScheduleId());
// // BB 4 (Flat) resets the match pointer so car BC 5 final destination and load is the same as last time
// Assert.assertEquals("Car BB 4 destination","Essex MA", c4.getDestinationName());
// Assert.assertEquals("Car BB 4 destination track","Essex Siding 1", c4.getDestinationTrackName());
// // new final destination and load for car BB 4
// Assert.assertEquals("Car BB 4 final destination","Danbury MA", c4.getFinalDestinationName());
// Assert.assertEquals("Car BB 4 final destination track","Danbury Siding 2", c4.getFinalDestinationTrackName());
// Assert.assertEquals("Car BB 4 next load","Metal", c4.getNextLoadName());
// Assert.assertEquals("Car BB 4 schedule id", "", c4.getScheduleId());
// // BC 5 (Boxcar)
// Assert.assertEquals("Car BC 5 destination","Essex MA", c5.getDestinationName());
// Assert.assertEquals("Car BC 5 destination track","Essex Siding 1", c5.getDestinationTrackName());
// // new final destination and load for car BC 5, same as BA 3
// Assert.assertEquals("Car BC 5 final destination","Bedford MA", c5.getFinalDestinationName());
// Assert.assertEquals("Car BC 5 final destination track","Bedford Siding 1", c5.getFinalDestinationTrackName());
// Assert.assertEquals("Car BC 5 next load","Screws", c5.getNextLoadName());
// Assert.assertEquals("Car BC 5 schedule id", "", c5.getScheduleId());
// // BD 6 (Boxcar) note second Boxcar
// Assert.assertEquals("Car BD 6 destination","Essex MA", c6.getDestinationName());
// Assert.assertEquals("Car BD 6 destination track","Essex Siding 1", c6.getDestinationTrackName());
// // new final destination and load for car BD 6
// Assert.assertEquals("Car BD 6 final destination","Danbury MA", c6.getFinalDestinationName());
// Assert.assertEquals("Car BD 6 final destination track","Danbury Siding 1", c6.getFinalDestinationTrackName());
// Assert.assertEquals("Car BC 6 next load", "Bolts", c6.getNextLoadName());
// Assert.assertEquals("Car BD 6 schedule id", "", c6.getScheduleId());
// // BA 7 (Boxcar) note 3rd Boxcar
// Assert.assertEquals("Car BA 7 destination","Essex MA", c7.getDestinationName());
// Assert.assertEquals("Car BA 7 destination track","Essex Siding 1", c7.getDestinationTrackName());
// // new final destination and load for car BA 7
// Assert.assertEquals("Car BA 7 final destination","Acton MA", c7.getFinalDestinationName());
// Assert.assertEquals("Car BA 7 final destination track","Acton Siding 1", c7.getFinalDestinationTrackName());
// Assert.assertEquals("Car BA 7 next load", "Metal", c7.getNextLoadName());
// Assert.assertEquals("Car BA 7 schedule id", "", c7.getScheduleId());
// // BB 8 (Boxcar) at Danbury to be added to train
// Assert.assertEquals("Car BB 8 destination","Essex MA", c8.getDestinationName());
// Assert.assertEquals("Car BB 8 destination track","Essex Siding 1", c8.getDestinationTrackName());
// // Should match schedule item 16c3
// Assert.assertEquals("Car BB 8 final destination","Bedford MA", c8.getFinalDestinationName());
// Assert.assertEquals("Car BB 8 final destination track","Bedford Siding 1", c8.getFinalDestinationTrackName());
// Assert.assertEquals("Car BB 8 next load", "Screws", c8.getNextLoadName());
// Assert.assertEquals("Car BB 8 schedule id", "", c8.getScheduleId());
// // BB 9 (Boxcar) at Danbury to be added to train
// Assert.assertEquals("Car BC 9 destination","Essex MA", c9.getDestinationName());
// Assert.assertEquals("Car BC 9 destination track","Essex Siding 1", c9.getDestinationTrackName());
// // Should match schedule item 16c4
// Assert.assertEquals("Car BC 9 final destination","Danbury MA", c9.getFinalDestinationName());
// Assert.assertEquals("Car BC 9 final destination track","Danbury Siding 1", c9.getFinalDestinationTrackName());
// Assert.assertEquals("Car BC 9 next load", "Bolts", c9.getNextLoadName());
// Assert.assertEquals("Car BC 9 schedule id", "", c9.getScheduleId());
//
// DanburyToEssexTrain.terminate();
//
// // check car destinations
// // BA 3 (Boxcar)
// Assert.assertEquals("Car BA 3 destination","", c3.getDestinationName());
// Assert.assertEquals("Car BA 3 destination track","", c3.getDestinationTrackName());
// // new final destination and load for car BA 3
// Assert.assertEquals("Car BA 3 final destination","Acton MA", c3.getFinalDestinationName());
// Assert.assertEquals("Car BA 3 final destination track","Acton Siding 1", c3.getFinalDestinationTrackName());
// Assert.assertEquals("Car BA 3 load","Metal", c3.getLoadName());
// Assert.assertEquals("Car BA 3 next load","", c3.getNextLoadName());
// Assert.assertEquals("Car BA 3 schedule id", "", c3.getScheduleId());
// // BB 4 (Flat)
// Assert.assertEquals("Car BB 4 destination","", c4.getDestinationName());
// Assert.assertEquals("Car BB 4 destination track","", c4.getDestinationTrackName());
// // new final destination and load for car BB 4
// Assert.assertEquals("Car BB 4 final destination","Danbury MA", c4.getFinalDestinationName());
// Assert.assertEquals("Car BB 4 final destination track","Danbury Siding 2", c4.getFinalDestinationTrackName());
// Assert.assertEquals("Car BB 4 load","Metal", c4.getLoadName());
// Assert.assertEquals("Car BB 4 next load","", c4.getNextLoadName());
// Assert.assertEquals("Car BB 4 schedule id", "", c4.getScheduleId());
// // BC 5 (Boxcar)
// Assert.assertEquals("Car BC 5 destination","", c5.getDestinationName());
// Assert.assertEquals("Car BC 5 destination track","", c5.getDestinationTrackName());
// // new final destination and load for car BC 5, same as BA 3
// Assert.assertEquals("Car BC 5 final destination","Bedford MA", c5.getFinalDestinationName());
// Assert.assertEquals("Car BC 5 final destination track","Bedford Siding 1", c5.getFinalDestinationTrackName());
// Assert.assertEquals("Car BC 5 load","Screws", c5.getLoadName());
// Assert.assertEquals("Car BC 5 next load","", c5.getNextLoadName());
// Assert.assertEquals("Car BC 5 schedule id", "", c5.getScheduleId());
// // BD 6 (Boxcar) note second Boxcar
// Assert.assertEquals("Car BD 6 destination","", c6.getDestinationName());
// Assert.assertEquals("Car BD 6 destination track","", c6.getDestinationTrackName());
// // new final destination and load for car BD 6
// Assert.assertEquals("Car BD 6 final destination","Danbury MA", c6.getFinalDestinationName());
// Assert.assertEquals("Car BD 6 final destination track","Danbury Siding 1", c6.getFinalDestinationTrackName());
// Assert.assertEquals("Car BC 6 load", "Bolts", c6.getLoadName());
// Assert.assertEquals("Car BC 6 next load", "", c6.getNextLoadName());
// Assert.assertEquals("Car BD 6 schedule id", "", c6.getScheduleId());
// // BA 7 (Boxcar) note 3rd Boxcar
// Assert.assertEquals("Car BA 7 destination","", c7.getDestinationName());
// Assert.assertEquals("Car BA 7 destination track","", c7.getDestinationTrackName());
// // new final destination and load for car BA 7
// Assert.assertEquals("Car BA 7 final destination","Acton MA", c7.getFinalDestinationName());
// Assert.assertEquals("Car BA 7 final destination track","Acton Siding 1", c7.getFinalDestinationTrackName());
// Assert.assertEquals("Car BA 7 load", "Metal", c7.getLoadName());
// Assert.assertEquals("Car BA 7 next load", "", c7.getNextLoadName());
// Assert.assertEquals("Car BA 7 schedule id", "", c7.getScheduleId());
// // BB 8 (Boxcar)
// Assert.assertEquals("Car BB 8 destination","", c8.getDestinationName());
// Assert.assertEquals("Car BB 8 destination track","", c8.getDestinationTrackName());
// // Should match schedule item 16c3
// Assert.assertEquals("Car BB 8 final destination","Bedford MA", c8.getFinalDestinationName());
// Assert.assertEquals("Car BB 8 final destination track","Bedford Siding 1", c8.getFinalDestinationTrackName());
// Assert.assertEquals("Car BB 8 load", "Screws", c8.getLoadName());
// Assert.assertEquals("Car BB 8 next load", "", c8.getNextLoadName());
// Assert.assertEquals("Car BB 8 schedule id", "", c8.getScheduleId());
// // BB 9 (Boxcar)
// Assert.assertEquals("Car BC 9 destination","", c9.getDestinationName());
// Assert.assertEquals("Car BC 9 destination track","", c9.getDestinationTrackName());
// // Should match schedule item 16c4
// Assert.assertEquals("Car BC 9 final destination","Danbury MA", c9.getFinalDestinationName());
// Assert.assertEquals("Car BC 9 final destination track","Danbury Siding 1", c9.getFinalDestinationTrackName());
// Assert.assertEquals("Car BC 9 load", "Bolts", c9.getLoadName());
// Assert.assertEquals("Car BC 9 next load", "", c9.getNextLoadName());
// Assert.assertEquals("Car BC 9 schedule id", "", c9.getScheduleId());
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class OperationsCarRouterTest method testRoutingWithSchedulesLocal.
/* This test confirms that schedules can be linked together.
* Note that there are schedules at Essex that are still active
* but not reachable because the Clinton to Danbury train is
* removed as part of this test.
* has 5 tracks, 3 sidings, yard, and an interchange track.
*
*/
public void testRoutingWithSchedulesLocal() {
TrainManager tmanager = TrainManager.instance();
CarManager cmanager = CarManager.instance();
LocationManager lmanager = LocationManager.instance();
loadLocationsTrainsAndCars();
List<Train> trains = tmanager.getTrainsByNameList();
Assert.assertEquals("confirm number of trains", 7, trains.size());
Car c3 = cmanager.getByRoadAndNumber("BA", "3");
Car c4 = cmanager.getByRoadAndNumber("BB", "4");
Car c5 = cmanager.getByRoadAndNumber("BC", "5");
Car c6 = cmanager.getByRoadAndNumber("BD", "6");
Car c7 = cmanager.getByRoadAndNumber("BA", "7");
Car c8 = cmanager.getByRoadAndNumber("BB", "8");
Car c9 = cmanager.getByRoadAndNumber("BC", "9");
// c3 (BA 3) is a Boxcar
c3.setLoadName("Cardboard");
// c4 (BB 4) is a Flat
c4.setLoadName("Trucks");
// c5 (BC 5) is a Boxcar
c5.setLoadName(CarLoads.instance().getDefaultEmptyName());
// c6 (BD 6) is a Boxcar
c6.setLoadName(CarLoads.instance().getDefaultEmptyName());
// c7 (7) is a Boxcar
c7.setLoadName(CarLoads.instance().getDefaultEmptyName());
// c8 (8) is a Boxcar
c8.setLoadName("Trucks");
// c9 (9) is a Boxcar
c9.setLoadName(CarLoads.instance().getDefaultEmptyName());
Location Acton = lmanager.getLocationByName("Acton MA");
Location Bedford = lmanager.getLocationByName("Bedford MA");
Location Clinton = lmanager.getLocationByName("Clinton MA");
Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
AS1.setTrainDirections(Track.NORTH + Track.SOUTH);
Track AS2 = Acton.getTrackByName("Acton Siding 2", Track.SPUR);
Track AS3 = Acton.addTrack("Acton Siding 3", Track.SPUR);
AS3.setLength(300);
Track AY = Acton.getTrackByName("Acton Yard", Track.YARD);
Track AI = Acton.getTrackByName("Acton Interchange", Track.INTERCHANGE);
// create schedules
ScheduleManager scheduleManager = ScheduleManager.instance();
Schedule schA = scheduleManager.newSchedule("Schedule Action");
ScheduleItem schAItem1 = schA.addItem("Boxcar");
schAItem1.setReceiveLoadName("Cardboard");
schAItem1.setShipLoadName("Scrap");
ScheduleItem schAItem2 = schA.addItem("Gon");
schAItem2.setReceiveLoadName("Trucks");
schAItem2.setShipLoadName("Tires");
schAItem2.setDestination(Bedford);
ScheduleItem schAItem3 = schA.addItem("Boxcar");
schAItem3.setReceiveLoadName("Trucks");
schAItem3.setShipLoadName("Wire");
schAItem3.setDestination(Clinton);
schAItem3.setDestinationTrack(CS1);
ScheduleItem schAItem4 = schA.addItem("Flat");
schAItem4.setReceiveLoadName("Trucks");
schAItem4.setShipLoadName("Coils");
schAItem4.setDestination(Bedford);
ScheduleItem schAItem5 = schA.addItem("Flat");
schAItem5.setReceiveLoadName("Coils");
schAItem5.setShipLoadName("Trucks");
schAItem5.setDestination(Bedford);
ScheduleItem schAItem6 = schA.addItem("Boxcar");
schAItem6.setReceiveLoadName("Scrap");
schAItem6.setShipLoadName("E");
ScheduleItem schAItem7 = schA.addItem("Boxcar");
schAItem7.setReceiveLoadName("Wire");
schAItem7.setShipLoadName("L");
// add schedules to tracks
AS1.setScheduleId(schA.getId());
AS1.setScheduleMode(Track.SEQUENTIAL);
AS2.setScheduleId(schA.getId());
AS2.setScheduleMode(Track.SEQUENTIAL);
AS3.setScheduleId(schA.getId());
// put Action Siding 3 into match mode
AS3.setScheduleMode(Track.MATCH);
// place cars
Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c5.setLocation(Acton, AS2));
Assert.assertEquals("Place car", Track.OKAY, c6.setLocation(Acton, AS2));
Assert.assertEquals("Place car", Track.OKAY, c7.setLocation(Acton, AS3));
Assert.assertEquals("Place car", Track.OKAY, c8.setLocation(Acton, AY));
Assert.assertEquals("Place car", Track.OKAY, c9.setLocation(Acton, AI));
// Build train
Train ActonToBedfordTrain = tmanager.getTrainByName("Acton to Bedford");
Route ActonToBeford = ActonToBedfordTrain.getRoute();
RouteLocation rl = ActonToBeford.getDepartsRouteLocation();
RouteLocation rd = ActonToBeford.getLastLocationByName("Bedford MA");
// increase the number of moves so all cars are used
rl.setMaxCarMoves(10);
rd.setMaxCarMoves(10);
// kill the Clinton to Danbury train
Train ClintonToDanburyTrain = tmanager.getTrainByName("Clinton to Danbury");
tmanager.deregister(ClintonToDanburyTrain);
ActonToBedfordTrain.build();
Assert.assertTrue("Acton train built", ActonToBedfordTrain.isBuilt());
// check cars
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Siding 2", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 3 load", "Cardboard", c3.getLoadName());
Assert.assertEquals("Car BA 3 next load", "Scrap", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Siding 3", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Bedford MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 load", "Trucks", c4.getLoadName());
Assert.assertEquals("Car BB 4 next load", "Coils", c4.getNextLoadName());
Assert.assertEquals("Car BC 5 destination", "Bedford MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Bedford Siding 1", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 load", "E", c5.getLoadName());
Assert.assertEquals("Car BC 5 next load", "", c5.getNextLoadName());
Assert.assertEquals("Car BD 6 destination", "Bedford MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Bedford Siding 2", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 load", "E", c6.getLoadName());
Assert.assertEquals("Car BD 6 next load", "", c6.getNextLoadName());
Assert.assertEquals("Car BA 7 destination", "Bedford MA", c7.getDestinationName());
Assert.assertEquals("Car BA 7 destination track", "Bedford Yard", c7.getDestinationTrackName());
Assert.assertEquals("Car BA 7 final destination", "", c7.getFinalDestinationName());
Assert.assertEquals("Car BA 7 final destination track", "", c7.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 7 load", "E", c7.getLoadName());
Assert.assertEquals("Car BA 7 next load", "", c7.getNextLoadName());
Assert.assertEquals("Car BB 8 destination", "Acton MA", c8.getDestinationName());
Assert.assertEquals("Car BB 8 destination track", "Acton Siding 3", c8.getDestinationTrackName());
Assert.assertEquals("Car BB 8 final destination", "Clinton MA", c8.getFinalDestinationName());
Assert.assertEquals("Car BB 8 final destination track", "Clinton Siding 1", c8.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 8 load", "Trucks", c8.getLoadName());
Assert.assertEquals("Car BB 8 next load", "Wire", c8.getNextLoadName());
Assert.assertEquals("Car BC 9 destination", "Bedford MA", c9.getDestinationName());
Assert.assertEquals("Car BC 9 destination track", "Bedford Interchange", c9.getDestinationTrackName());
Assert.assertEquals("Car BC 9 final destination", "", c9.getFinalDestinationName());
Assert.assertEquals("Car BC 9 final destination track", "", c9.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 9 load", "E", c9.getLoadName());
Assert.assertEquals("Car BC 9 next load", "", c9.getNextLoadName());
ActonToBedfordTrain.terminate();
// Build train
Train BedfordToActonTrain = tmanager.newTrain("BedfordToActonToBedford");
Route BedfordToActon = RouteManager.instance().newRoute("BedfordToActonToBedford");
RouteLocation rlB2 = BedfordToActon.addLocation(Bedford);
RouteLocation rlA2 = BedfordToActon.addLocation(Acton);
RouteLocation rlB3 = BedfordToActon.addLocation(Bedford);
// increase the number of moves so all cars are used
rlB2.setMaxCarMoves(10);
rlA2.setMaxCarMoves(10);
rlB3.setMaxCarMoves(10);
BedfordToActonTrain.setRoute(BedfordToActon);
BedfordToActonTrain.build();
// check cars
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Siding 3", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 3 load", "Scrap", c3.getLoadName());
Assert.assertEquals("Car BA 3 next load", "E", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 destination", "Bedford MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Bedford Yard", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 load", "Coils", c4.getLoadName());
Assert.assertEquals("Car BB 4 next load", "", c4.getNextLoadName());
Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Acton Yard", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 load", "L", c5.getLoadName());
Assert.assertEquals("Car BC 5 next load", "", c5.getNextLoadName());
Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "", c6.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 load", "L", c6.getLoadName());
Assert.assertEquals("Car BD 6 next load", "", c6.getNextLoadName());
Assert.assertEquals("Car BA 7 destination", "Acton MA", c7.getDestinationName());
Assert.assertEquals("Car BA 7 destination track", "Acton Yard", c7.getDestinationTrackName());
Assert.assertEquals("Car BA 7 final destination", "", c7.getFinalDestinationName());
Assert.assertEquals("Car BA 7 final destination track", "", c7.getFinalDestinationTrackName());
Assert.assertEquals("Car BA 7 load", "E", c7.getLoadName());
Assert.assertEquals("Car BA 7 next load", "", c7.getNextLoadName());
Assert.assertEquals("Car BB 8 destination", "Bedford MA", c8.getDestinationName());
Assert.assertEquals("Car BB 8 destination track", "Bedford Interchange", c8.getDestinationTrackName());
Assert.assertEquals("Car BB 8 final destination", "Clinton MA", c8.getFinalDestinationName());
Assert.assertEquals("Car BB 8 final destination track", "Clinton Siding 1", c8.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 8 load", "Wire", c8.getLoadName());
Assert.assertEquals("Car BB 8 next load", "", c8.getNextLoadName());
Assert.assertEquals("Car BC 9 destination", "Acton MA", c9.getDestinationName());
Assert.assertEquals("Car BC 9 destination track", "Acton Interchange", c9.getDestinationTrackName());
Assert.assertEquals("Car BC 9 final destination", "", c9.getFinalDestinationName());
Assert.assertEquals("Car BC 9 final destination track", "", c9.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 9 load", "E", c9.getLoadName());
Assert.assertEquals("Car BC 9 next load", "", c9.getNextLoadName());
BedfordToActonTrain.terminate();
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class OperationsCarRouterTest method testRoutingWithSimpleSchedules.
/*
* This test creates 4 schedules, and each schedule only has one item.
* Two cars are used a boxcar and a flat. They both start with a load of
* "Food". They should be routed to the correct schedule that is demanding
* the car type and load.
*/
public void testRoutingWithSimpleSchedules() {
TrainManager tmanager = TrainManager.instance();
CarManager cmanager = CarManager.instance();
LocationManager lmanager = LocationManager.instance();
loadLocationsTrainsAndCars();
List<Train> trains = tmanager.getTrainsByNameList();
Assert.assertEquals("confirm number of trains", 7, trains.size());
Train ActonTrain = tmanager.getTrainByName("Acton Local");
Train ActonToBedfordTrain = tmanager.getTrainByName("Acton to Bedford");
Train BedfordToClintonTrain = tmanager.getTrainByName("Bedford to Clinton");
Train ClintonToDanburyTrain = tmanager.getTrainByName("Clinton to Danbury");
Train DanburyToEssexTrain = tmanager.getTrainByName("Danbury to Essex");
Train EssexToFoxboroTrain = tmanager.getTrainByName("Essex to Foxboro");
Car c3 = cmanager.getByRoadAndNumber("BA", "3");
Car c4 = cmanager.getByRoadAndNumber("BB", "4");
Location Acton = lmanager.getLocationByName("Acton MA");
Location Clinton = lmanager.getLocationByName("Clinton MA");
Location Danbury = lmanager.getLocationByName("Danbury MA");
Location Essex = lmanager.getLocationByName("Essex MA");
Location Foxboro = lmanager.getLocationByName("Foxboro MA");
Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
Track DS1 = Danbury.getTrackByName("Danbury Siding 1", Track.SPUR);
Track DS2 = Danbury.getTrackByName("Danbury Siding 2", Track.SPUR);
Track ES1 = Essex.getTrackByName("Essex Siding 1", Track.SPUR);
Track ES2 = Essex.getTrackByName("Essex Siding 2", Track.SPUR);
Track FS1 = Foxboro.getTrackByName("Foxboro Siding 1", Track.SPUR);
// set the depart track Acton to service by local train only
AS1.setTrainDirections(0);
// create schedules
ScheduleManager scheduleManager = ScheduleManager.instance();
Schedule schA = scheduleManager.newSchedule("Schedule A");
ScheduleItem schAItem1 = schA.addItem("Boxcar");
schAItem1.setReceiveLoadName("Food");
schAItem1.setShipLoadName("Metal");
schAItem1.setDestination(Danbury);
schAItem1.setDestinationTrack(DS2);
Schedule schB = scheduleManager.newSchedule("Schedule B");
ScheduleItem schBItem1 = schB.addItem("Flat");
schBItem1.setReceiveLoadName("Food");
schBItem1.setShipLoadName("Junk");
schBItem1.setDestination(Foxboro);
schBItem1.setDestinationTrack(FS1);
Schedule schC = scheduleManager.newSchedule("Schedule C");
ScheduleItem schCItem1 = schC.addItem("Boxcar");
schCItem1.setShipLoadName("Screws");
schCItem1.setDestination(Essex);
Schedule schD = scheduleManager.newSchedule("Schedule D");
ScheduleItem schDItem1 = schD.addItem("Boxcar");
schDItem1.setReceiveLoadName("Screws");
schDItem1.setShipLoadName("Nails");
schDItem1.setWait(1);
schDItem1.setDestination(Foxboro);
schDItem1.setDestinationTrack(FS1);
// Add schedule to tracks
DS1.setScheduleId(schB.getId());
DS2.setScheduleId(schC.getId());
ES1.setScheduleId(schD.getId());
ES2.setScheduleId(schA.getId());
CS1.setScheduleId(schA.getId());
// bias track
ES2.setMoves(0);
CS1.setMoves(1);
DS2.setMoves(50);
// place cars
Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
// c3 (BA 3) is a Boxcar
// Track Essex Siding 2 schedule is demanding this car
c3.setLoadName("Food");
c3.setReturnWhenEmptyDestination(Foxboro);
// c4 (BB 4) is a Flat
// Track Danbury Siding 1 schedule is demanding this car
c4.setLoadName("Food");
// build train
// Car c3 should be routed to Essex using 5 trains
ActonTrain.build();
Assert.assertTrue("Acton train built", ActonTrain.isBuilt());
// check car destinations
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Interchange", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Essex MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Essex Siding 2", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Interchange", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Danbury MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Danbury Siding 1", c4.getFinalDestinationTrackName());
ActonTrain.reset();
// check car destinations after reset
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
// bias track
ES2.setMoves(100);
ActonTrain.reset();
// build train
ActonTrain.build();
Assert.assertTrue("Acton train built", ActonTrain.isBuilt());
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Interchange", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Clinton MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Clinton Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Interchange", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Danbury MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Danbury Siding 1", c4.getFinalDestinationTrackName());
// check next loads
//Assert.assertEquals("Car BA 3 load","Metal", c3.getNextLoad());
//Assert.assertEquals("Car BB 4 load","Junk", c4.getNextLoad());
ActonTrain.terminate();
// check destinations
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Clinton MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Clinton Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Danbury MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Danbury Siding 1", c4.getFinalDestinationTrackName());
// check load
Assert.assertEquals("Car BA 3 load", "Food", c3.getLoadName());
Assert.assertEquals("Car BB 4 load", "Food", c4.getLoadName());
// check next loads
Assert.assertEquals("Car BA 3 load", "", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 load", "", c4.getNextLoadName());
// check car's location
Assert.assertEquals("Car BA 3 location", "Acton Interchange", c3.getTrackName());
Assert.assertEquals("Car BB 4 location", "Acton Interchange", c4.getTrackName());
ActonToBedfordTrain.build();
ActonToBedfordTrain.terminate();
// check destinations
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
// schedule at Clinton (schedule A) forwards car BA 3 to Danbury, load Metal
Assert.assertEquals("Car BA 3 final destination", "Clinton MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Clinton Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Danbury MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Danbury Siding 1", c4.getFinalDestinationTrackName());
// check load
Assert.assertEquals("Car BA 3 load", "Food", c3.getLoadName());
Assert.assertEquals("Car BB 4 load", "Food", c4.getLoadName());
// check next loads
Assert.assertEquals("Car BA 3 load", "", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 load", "", c4.getNextLoadName());
BedfordToClintonTrain.build();
BedfordToClintonTrain.terminate();
// check destinations
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
// schedule at Danbury (schedule C) forwards car BA 3 to Essex, no track specified, load Screws
// schedule at Clinton (schedule A) forwards car BA 3 to Danbury, load Metal
Assert.assertEquals("Car BA 3 final destination", "Danbury MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Danbury Siding 2", c3.getFinalDestinationTrackName());
// schedule at Danbury (schedule B) forwards car BB 4 to Foxboro load Junk
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Danbury MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Danbury Siding 1", c4.getFinalDestinationTrackName());
// check load
Assert.assertEquals("Car BA 3 load", "Metal", c3.getLoadName());
Assert.assertEquals("Car BB 4 load", "Food", c4.getLoadName());
// check next loads
Assert.assertEquals("Car BA 3 load", "", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 load", "", c4.getNextLoadName());
// check car's location
Assert.assertEquals("Car BA 3 location", "Clinton Siding 1", c3.getTrackName());
Assert.assertEquals("Car BB 4 location", "Clinton Interchange", c4.getTrackName());
ClintonToDanburyTrain.build();
ClintonToDanburyTrain.terminate();
// Train has arrived at Danbury, check destinations
// schedule at Danbury (schedule C) forwards car BA 3 to Essex, no track specified, load Screws
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Essex MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
// schedule at Danbury (schedule B) forward car BB 4 to Foxboro Siding 1.
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Foxboro MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Foxboro Siding 1", c4.getFinalDestinationTrackName());
// check load
Assert.assertEquals("Car BA 3 load", "Screws", c3.getLoadName());
Assert.assertEquals("Car BB 4 load", "Junk", c4.getLoadName());
// check next loads
Assert.assertEquals("Car BA 3 load", "", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 load", "", c4.getNextLoadName());
// check car's location
Assert.assertEquals("Car BA 3 location", "Danbury Siding 2", c3.getTrackName());
Assert.assertEquals("Car BB 4 location", "Danbury Siding 1", c4.getTrackName());
DanburyToEssexTrain.build();
// schedule D at Essex Siding 1 is requesting load Screws, ship Nails then forward car to Foxboro Siding 1
Assert.assertEquals("Car BA 3 destination track", "Essex Siding 1", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Foxboro MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Foxboro Siding 1", c3.getFinalDestinationTrackName());
// check next loads
Assert.assertEquals("Car BA 3 load", "Nails", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 load", "", c4.getNextLoadName());
// check next wait
Assert.assertEquals("Car BA 3 has wait", 1, c3.getNextWait());
Assert.assertEquals("Car BB 4 has no wait", 0, c4.getNextWait());
DanburyToEssexTrain.terminate();
// Train has arrived at Essex, check destinations
// schedule at Essex (schedule D) forwards car BA 3 to Foxboro Siding 1 load Nails, wait = 1
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Foxboro MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Foxboro Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Foxboro MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Foxboro Siding 1", c4.getFinalDestinationTrackName());
// check load
// wait of 1 delays load change
Assert.assertEquals("Car BA 3 load", "Screws", c3.getLoadName());
Assert.assertEquals("Car BB 4 load", "Junk", c4.getLoadName());
// check next loads
// wait of 1 delays load change
Assert.assertEquals("Car BA 3 load", "Nails", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 load", "", c4.getNextLoadName());
// check wait
Assert.assertEquals("Car BA 3 has wait", 1, c3.getWait());
Assert.assertEquals("Car BB 4 has no wait", 0, c4.getWait());
// check next wait
Assert.assertEquals("Car BA 3 has wait", 0, c3.getNextWait());
Assert.assertEquals("Car BB 4 has no wait", 0, c4.getNextWait());
// check car's location
Assert.assertEquals("Car BA 3 location", "Essex Siding 1", c3.getTrackName());
Assert.assertEquals("Car BB 4 location", "Essex Interchange", c4.getTrackName());
EssexToFoxboroTrain.build();
// confirm that only BB 4 is in train, BA 3 has wait = 1
Assert.assertEquals("Car BA 3 not in train", null, c3.getTrain());
Assert.assertEquals("Car BB 4 in train", EssexToFoxboroTrain, c4.getTrain());
EssexToFoxboroTrain.terminate();
// Train has arrived at Foxboro, check destinations
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Foxboro MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Foxboro Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
// check load
Assert.assertEquals("Car BA 3 load", "Nails", c3.getLoadName());
Assert.assertEquals("Car BB 4 load", "E", c4.getLoadName());
// check next loads
Assert.assertEquals("Car BA 3 load", "", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 load", "", c4.getNextLoadName());
// check wait
Assert.assertEquals("Car BA 3 has no wait", 0, c3.getWait());
Assert.assertEquals("Car BB 4 has no wait", 0, c4.getWait());
// check car's location
Assert.assertEquals("Car BA 3 location", "Essex Siding 1", c3.getTrackName());
Assert.assertEquals("Car BB 4 location", "Foxboro Siding 1", c4.getTrackName());
EssexToFoxboroTrain.build();
// confirm that only BA 3 is in train
Assert.assertEquals("Car BA 3 in train", EssexToFoxboroTrain, c3.getTrain());
Assert.assertEquals("Car BB 4 not in train", null, c4.getTrain());
EssexToFoxboroTrain.terminate();
// Train has arrived again at Foxboro, check destinations
Assert.assertEquals("Car BA 3 destination", "", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "", c3.getDestinationTrackName());
// Car BA 3 has return when empty destination of Foxboro, no track
Assert.assertEquals("Car BA 3 final destination", "Foxboro MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "", c4.getFinalDestinationTrackName());
// check load
Assert.assertEquals("Car BA 3 load", "E", c3.getLoadName());
Assert.assertEquals("Car BB 4 load", "E", c4.getLoadName());
// check next loads
Assert.assertEquals("Car BA 3 load", "", c3.getNextLoadName());
Assert.assertEquals("Car BB 4 load", "", c4.getNextLoadName());
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class OperationsCarRouterTest method testRoutingWithSchedules.
/*
* Using the setup from the previous tests, use trains and schedules to move
* cars. This test creates 1 schedule with multiple items. Four cars are
* used, three boxcars and a flat. They should be routed to the correct
* schedule that is demanding the car type and load.
*/
public void testRoutingWithSchedules() {
TrainManager tmanager = TrainManager.instance();
CarManager cmanager = CarManager.instance();
LocationManager lmanager = LocationManager.instance();
loadLocationsTrainsAndCars();
List<Train> trains = tmanager.getTrainsByNameList();
Assert.assertEquals("confirm number of trains", 7, trains.size());
Train ActonTrain = tmanager.getTrainByName("Acton Local");
Train ActonToBedfordTrain = tmanager.getTrainByName("Acton to Bedford");
Train BedfordToClintonTrain = tmanager.getTrainByName("Bedford to Clinton");
Car c3 = cmanager.getByRoadAndNumber("BA", "3");
Car c4 = cmanager.getByRoadAndNumber("BB", "4");
Car c5 = cmanager.getByRoadAndNumber("BC", "5");
Car c6 = cmanager.getByRoadAndNumber("BD", "6");
Location Acton = lmanager.getLocationByName("Acton MA");
Location Clinton = lmanager.getLocationByName("Clinton MA");
Location Danbury = lmanager.getLocationByName("Danbury MA");
Location Essex = lmanager.getLocationByName("Essex MA");
Track AS1 = Acton.getTrackByName("Acton Siding 1", Track.SPUR);
Track CS1 = Clinton.getTrackByName("Clinton Siding 1", Track.SPUR);
Track DS1 = Danbury.getTrackByName("Danbury Siding 1", Track.SPUR);
Track DS2 = Danbury.getTrackByName("Danbury Siding 2", Track.SPUR);
Track ES1 = Essex.getTrackByName("Essex Siding 1", Track.SPUR);
Track ES2 = Essex.getTrackByName("Essex Siding 2", Track.SPUR);
// set the depart track Acton to service by local train only
AS1.setTrainDirections(0);
// create schedules
ScheduleManager scheduleManager = ScheduleManager.instance();
Schedule schA = scheduleManager.newSchedule("Schedule AA");
ScheduleItem schAItem1 = schA.addItem("Boxcar");
schAItem1.setReceiveLoadName("Empty");
schAItem1.setShipLoadName("Metal");
schAItem1.setDestination(Acton);
schAItem1.setDestinationTrack(AS1);
ScheduleItem schAItem2 = schA.addItem("Flat");
schAItem2.setReceiveLoadName("Junk");
schAItem2.setShipLoadName("Metal");
schAItem2.setDestination(Danbury);
schAItem2.setDestinationTrack(DS2);
ScheduleItem schAItem3 = schA.addItem("Boxcar");
schAItem3.setReceiveLoadName("Boxes");
schAItem3.setShipLoadName("Screws");
schAItem3.setDestination(Danbury);
schAItem3.setDestinationTrack(DS1);
// Add schedule to tracks
CS1.setScheduleId(schA.getId());
CS1.setScheduleMode(Track.SEQUENTIAL);
DS1.setScheduleId("");
DS2.setScheduleId("");
ES1.setScheduleId("");
ES2.setScheduleId("");
// c3 (BA 3) is a Boxcar
c3.setLoadName("Empty");
// c4 (BB 4) is a Flat
c4.setLoadName("Junk");
c5.setLoadName("Boxes");
c6.setLoadName("Empty");
// place cars
Assert.assertEquals("Place car", Track.OKAY, c3.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c4.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c5.setLocation(Acton, AS1));
Assert.assertEquals("Place car", Track.OKAY, c6.setLocation(Acton, AS1));
// note car move count is exactly the same order as schedule
// build train
ActonTrain.build();
Assert.assertTrue("Acton train built", ActonTrain.isBuilt());
// check car destinations
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Interchange", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "Clinton MA", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "Clinton Siding 1", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Interchange", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Clinton MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Clinton Siding 1", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Acton Interchange", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "Clinton MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "Clinton Siding 1", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "Clinton MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "Clinton Siding 1", c6.getFinalDestinationTrackName());
// check car schedule ids
Assert.assertEquals("Car BA 3 schedule id", schAItem1.getId(), c3.getScheduleItemId());
Assert.assertEquals("Car BB 4 schedule id", schAItem2.getId(), c4.getScheduleItemId());
Assert.assertEquals("Car BC 5 schedule id", schAItem3.getId(), c5.getScheduleItemId());
Assert.assertEquals("Car BD 6 schedule id", schAItem1.getId(), c6.getScheduleItemId());
ActonTrain.reset();
// Next car in schedule is flat car
// build train
ActonTrain.build();
Assert.assertTrue("Acton train built", ActonTrain.isBuilt());
// check car destinations
Assert.assertEquals("Car BA 3 destination", "Acton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Acton Yard", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Acton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Acton Interchange", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Clinton MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Clinton Siding 1", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 destination", "Acton MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Acton Interchange", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "Clinton MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "Clinton Siding 1", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 destination", "Acton MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Acton Interchange", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "Clinton MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "Clinton Siding 1", c6.getFinalDestinationTrackName());
// check car schedule ids
Assert.assertEquals("Car BA 3 schedule id", "", c3.getScheduleItemId());
Assert.assertEquals("Car BB 4 schedule id", schAItem2.getId(), c4.getScheduleItemId());
Assert.assertEquals("Car BC 5 schedule id", schAItem3.getId(), c5.getScheduleItemId());
Assert.assertEquals("Car BD 6 schedule id", schAItem1.getId(), c6.getScheduleItemId());
ActonTrain.terminate();
// move the cars to Bedford
ActonToBedfordTrain.build();
Assert.assertTrue("Bedford train built", ActonToBedfordTrain.isBuilt());
// check car destinations
Assert.assertEquals("Car BA 3 destination", "Bedford MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Bedford Yard", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Bedford MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Bedford Interchange", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Clinton MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Clinton Siding 1", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 destination", "Bedford MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Bedford Interchange", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "Clinton MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "Clinton Siding 1", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 destination", "Bedford MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Bedford Interchange", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "Clinton MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "Clinton Siding 1", c6.getFinalDestinationTrackName());
// check car schedule ids
Assert.assertEquals("Car BA 3 schedule id", "", c3.getScheduleItemId());
Assert.assertEquals("Car BB 4 schedule id", schAItem2.getId(), c4.getScheduleItemId());
Assert.assertEquals("Car BC 5 schedule id", schAItem3.getId(), c5.getScheduleItemId());
Assert.assertEquals("Car BD 6 schedule id", schAItem1.getId(), c6.getScheduleItemId());
ActonToBedfordTrain.terminate();
// move the cars to Bedford
BedfordToClintonTrain.build();
Assert.assertTrue("Bedford train built", BedfordToClintonTrain.isBuilt());
// check car destinations
Assert.assertEquals("Car BA 3 destination", "Clinton MA", c3.getDestinationName());
Assert.assertEquals("Car BA 3 destination track", "Clinton Yard", c3.getDestinationTrackName());
Assert.assertEquals("Car BA 3 final destination", "", c3.getFinalDestinationName());
Assert.assertEquals("Car BA 3 final destination track", "", c3.getFinalDestinationTrackName());
Assert.assertEquals("Car BB 4 destination", "Clinton MA", c4.getDestinationName());
Assert.assertEquals("Car BB 4 destination track", "Clinton Siding 1", c4.getDestinationTrackName());
Assert.assertEquals("Car BB 4 final destination", "Danbury MA", c4.getFinalDestinationName());
Assert.assertEquals("Car BB 4 final destination track", "Danbury Siding 2", c4.getFinalDestinationTrackName());
Assert.assertEquals("Car BC 5 destination", "Clinton MA", c5.getDestinationName());
Assert.assertEquals("Car BC 5 destination track", "Clinton Siding 1", c5.getDestinationTrackName());
Assert.assertEquals("Car BC 5 final destination", "Danbury MA", c5.getFinalDestinationName());
Assert.assertEquals("Car BC 5 final destination track", "Danbury Siding 1", c5.getFinalDestinationTrackName());
Assert.assertEquals("Car BD 6 destination", "Clinton MA", c6.getDestinationName());
Assert.assertEquals("Car BD 6 destination track", "Clinton Siding 1", c6.getDestinationTrackName());
Assert.assertEquals("Car BD 6 final destination", "Acton MA", c6.getFinalDestinationName());
Assert.assertEquals("Car BD 6 final destination track", "Acton Siding 1", c6.getFinalDestinationTrackName());
// check car schedule ids
Assert.assertEquals("Car BA 3 schedule id", "", c3.getScheduleItemId());
Assert.assertEquals("Car BB 4 schedule id", "", c4.getScheduleItemId());
Assert.assertEquals("Car BC 5 schedule id", "", c5.getScheduleItemId());
Assert.assertEquals("Car BD 6 schedule id", "", c6.getScheduleItemId());
BedfordToClintonTrain.terminate();
}
use of jmri.jmrit.operations.locations.schedules.ScheduleItem in project JMRI by JMRI.
the class TrainTest method testScheduleLoads.
public void testScheduleLoads() {
TrainManager tmanager = TrainManager.instance();
RouteManager rmanager = RouteManager.instance();
LocationManager lmanager = LocationManager.instance();
CarManager cmanager = CarManager.instance();
ScheduleManager smanager = ScheduleManager.instance();
CarTypes ct = CarTypes.instance();
ct.addName("Boxcar");
ct.addName("Gon");
ct.addName("Coil Car");
ct.addName("Flat Car");
// create schedules
Schedule sch1 = smanager.newSchedule("Schedule 1");
ScheduleItem sch1Item1 = sch1.addItem("Boxcar");
// request a UP Boxcar
sch1Item1.setRoadName("UP");
ScheduleItem sch1Item2 = sch1.addItem("Flat Car");
// request an empty car and load it with Scrap
sch1Item2.setReceiveLoadName("E");
sch1Item2.setShipLoadName("Scrap");
ScheduleItem sch1Item3 = sch1.addItem("Gon");
// request a loaded car and load it with Tin
sch1Item3.setReceiveLoadName("L");
sch1Item3.setShipLoadName("Tin");
// Allows c13 which is part of a kernel to get a new load
CarLoads.instance().addName("Gon", "Tin");
Schedule sch2 = smanager.newSchedule("Schedule 2");
ScheduleItem sch2Item1 = sch2.addItem("Coil Car");
sch2Item1.setCount(2);
sch2.addItem("Boxcar");
// Create locations used
Location loc1;
loc1 = lmanager.newLocation("New Westford");
loc1.setTrainDirections(DIRECTION_ALL);
// loc1.addTypeName("Flat Car");
Location loc2;
loc2 = lmanager.newLocation("New Chelmsford");
loc2.setTrainDirections(DIRECTION_ALL);
Location loc3;
loc3 = lmanager.newLocation("New Bedford");
loc3.setTrainDirections(DIRECTION_ALL);
Track loc1trk1;
loc1trk1 = loc1.addTrack("Westford Yard 1", Track.YARD);
loc1trk1.setTrainDirections(Track.WEST + Track.EAST);
loc1trk1.setLength(900);
// loc1trk1.addTypeName("Flat Car");
Track loc1trk2;
loc1trk2 = loc1.addTrack("Westford Yard 2", Track.YARD);
loc1trk2.setTrainDirections(Track.WEST + Track.EAST);
loc1trk2.setLength(500);
loc1trk2.deleteTypeName("Coil Car");
Track loc1trk3;
loc1trk3 = loc1.addTrack("Westford Express 3", Track.SPUR);
loc1trk3.setTrainDirections(Track.WEST + Track.EAST);
loc1trk3.setLength(300);
loc1trk3.deleteTypeName("Gon");
loc1trk3.deleteTypeName("Coil Car");
Track loc1trk4;
loc1trk4 = loc1.addTrack("Westford Express 4", Track.SPUR);
loc1trk4.setTrainDirections(Track.WEST + Track.EAST);
loc1trk4.setLength(300);
loc1trk4.deleteTypeName("Gon");
loc1trk4.deleteTypeName("Coil Car");
Track loc2trk1;
loc2trk1 = loc2.addTrack("Chelmsford Freight 1", Track.SPUR);
loc2trk1.setTrainDirections(Track.WEST + Track.EAST);
loc2trk1.setLength(900);
loc2trk1.deleteTypeName("Coil Car");
loc2trk1.setScheduleId(sch1.getId());
loc2trk1.setScheduleMode(Track.SEQUENTIAL);
// start the schedule with 2nd item Flat Car
loc2trk1.setScheduleItemId(sch1.getItemsBySequenceList().get(1).getId());
Track loc2trk2;
loc2trk2 = loc2.addTrack("Chelmsford Freight 2", Track.SPUR);
loc2trk2.setTrainDirections(Track.WEST + Track.EAST);
loc2trk2.setLength(900);
loc2trk2.deleteTypeName("Coil Car");
loc2trk2.setScheduleId(sch1.getId());
loc2trk2.setScheduleMode(Track.SEQUENTIAL);
// start the schedule with 3rd item Gon
loc2trk2.setScheduleItemId(sch1.getItemsBySequenceList().get(2).getId());
Track loc2trk3;
loc2trk3 = loc2.addTrack("Chelmsford Yard 3", Track.YARD);
loc2trk3.setTrainDirections(Track.WEST + Track.EAST);
loc2trk3.setLength(900);
loc2trk3.deleteTypeName("Gon");
loc2trk3.deleteTypeName("Coil Car");
Track loc2trk4;
loc2trk4 = loc2.addTrack("Chelmsford Freight 4", Track.SPUR);
loc2trk4.setTrainDirections(Track.WEST + Track.EAST);
loc2trk4.setLength(900);
loc2trk4.setScheduleId(sch2.getId());
loc2trk4.setScheduleMode(Track.SEQUENTIAL);
Track loc3trk1;
loc3trk1 = loc3.addTrack("Bedford Yard 1", Track.STAGING);
loc3trk1.setTrainDirections(Track.WEST + Track.EAST);
loc3trk1.setLength(900);
loc3trk1.setRemoveCustomLoadsEnabled(true);
// Create route with 2 location
Route rte1;
rte1 = rmanager.newRoute("Two Location Route");
RouteLocation rl1 = rte1.addLocation(loc1);
rl1.setTrainDirection(RouteLocation.EAST);
rl1.setMaxCarMoves(12);
// set the train icon coordinates
rl1.setTrainIconX(25);
rl1.setTrainIconY(75);
RouteLocation rl2 = rte1.addLocation(loc2);
rl2.setTrainDirection(RouteLocation.EAST);
rl2.setMaxCarMoves(12);
// set the train icon coordinates
rl2.setTrainIconX(75);
rl2.setTrainIconY(75);
// Create train
Train train1;
train1 = tmanager.newTrain("NWNC");
train1.setRoute(rte1);
// Set up 13 cars
Car c1 = new Car("BM", "S1");
c1.setTypeName("Gon");
c1.setLength("90");
c1.setMoves(13);
c1.setLoadName("L");
cmanager.register(c1);
Car c2 = new Car("UP", "S2");
c2.setTypeName("Boxcar");
c2.setLength("80");
c2.setMoves(12);
cmanager.register(c2);
Car c3 = new Car("XP", "S3");
c3.setTypeName("Flat Car");
c3.setLength("70");
c3.setMoves(0);
c3.setLoadName("L");
// force this car to Chelmsford
c3.setDestination(loc2, null);
cmanager.register(c3);
Car c4 = new Car("PU", "S4");
c4.setTypeName("Boxcar");
c4.setLength("60");
c4.setMoves(10);
cmanager.register(c4);
// place two cars in a kernel
Kernel k1 = cmanager.newKernel("TwoCars");
Car c5 = new Car("UP", "S5");
c5.setTypeName("Gon");
c5.setLength("50");
c5.setMoves(9);
c5.setLoadName("L");
c5.setKernel(k1);
cmanager.register(c5);
Car c6 = new Car("CP", "S6");
c6.setTypeName("Boxcar");
c6.setLength("40");
c6.setMoves(8);
c6.setLoadName("L");
cmanager.register(c6);
Car c7 = new Car("UP", "S7");
c7.setTypeName("Boxcar");
c7.setLength("50");
c7.setMoves(7);
cmanager.register(c7);
Car c8 = new Car("XP", "S8");
c8.setTypeName("Gon");
c8.setLength("60");
c8.setMoves(6);
cmanager.register(c8);
Car c9 = new Car("XP", "S9");
c9.setTypeName("Flat Car");
c9.setLength("90");
c9.setMoves(5);
c9.setLoadName("E");
cmanager.register(c9);
Car c10 = new Car("CP", "S10");
c10.setTypeName("Coil Car");
c10.setLength("40");
c10.setMoves(2);
c10.setLoadName("L");
cmanager.register(c10);
Car c11 = new Car("CP", "S11");
c11.setTypeName("Coil Car");
c11.setLength("40");
c11.setMoves(3);
c11.setLoadName("Coils");
cmanager.register(c11);
Car c12 = new Car("CP", "S12");
c12.setTypeName("Coil Car");
c12.setLength("40");
c12.setMoves(4);
cmanager.register(c12);
// place car in kernel with c5
Car c13 = new Car("UP", "S13");
c13.setTypeName("Gon");
c13.setLength("50");
c13.setMoves(1);
c13.setLoadName("L");
c13.setKernel(k1);
cmanager.register(c13);
// place the cars in the yards
Assert.assertEquals("Place c1", Track.OKAY, c1.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c2", Track.OKAY, c2.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c3", Track.OKAY, c3.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c4", Track.OKAY, c4.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c5", Track.OKAY, c5.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c6", Track.OKAY, c6.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c7", Track.OKAY, c7.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c8", Track.OKAY, c8.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c9", Track.OKAY, c9.setLocation(loc1, loc1trk2));
Assert.assertEquals("Place c10", Track.OKAY, c10.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c11", Track.OKAY, c11.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c12", Track.OKAY, c12.setLocation(loc1, loc1trk1));
Assert.assertEquals("Place c13", Track.OKAY, c13.setLocation(loc1, loc1trk2));
train1.build();
// Schedule sch1 should cause c2 to be delivered to Chelmsford Freight 2
Assert.assertEquals("c2 destination", "Chelmsford Freight 2", c2.getDestinationTrackName());
Assert.assertEquals("c2 next load", "", c2.getNextLoadName());
// Schedule sch1 and sch2 should reject c3, to be delivered to Chelmsford Yard 3
Assert.assertEquals("c3 destination", "Chelmsford Yard 3", c3.getDestinationTrackName());
Assert.assertEquals("c3 next load", "", c3.getNextLoadName());
Assert.assertEquals("c4 destination", "Chelmsford Yard 3", c4.getDestinationTrackName());
// Schedule sch1 should cause c5 & c13 to be delivered to Chelmsford Freight 2
Assert.assertEquals("c5 destination", "Chelmsford Freight 2", c5.getDestinationTrackName());
Assert.assertEquals("c5 next load", "Tin", c5.getNextLoadName());
Assert.assertEquals("c6 destination", "Chelmsford Yard 3", c6.getDestinationTrackName());
Assert.assertEquals("c7 destination", "Chelmsford Freight 4", c7.getDestinationTrackName());
Assert.assertEquals("c9 destination", "Chelmsford Freight 1", c9.getDestinationTrackName());
Assert.assertEquals("c9 next load", "Scrap", c9.getNextLoadName());
Assert.assertEquals("c10 destination", "Chelmsford Freight 4", c10.getDestinationTrackName());
Assert.assertEquals("c11 destination", "Chelmsford Freight 4", c11.getDestinationTrackName());
// C13 is part of kernel, load will flip between E and L
Assert.assertEquals("c13 destination", "Chelmsford Freight 2", c13.getDestinationTrackName());
Assert.assertEquals("c13 next load", "Tin", c13.getNextLoadName());
// move and terminate train
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track", "Chelmsford Freight 1", c1.getTrackName());
Assert.assertEquals("c1 load", "Tin", c1.getLoadName());
Assert.assertEquals("c2 track", "Chelmsford Freight 2", c2.getTrackName());
Assert.assertEquals("c2 load", "L", c2.getLoadName());
Assert.assertEquals("c3 track", "Chelmsford Yard 3", c3.getTrackName());
Assert.assertEquals("c3 load", "L", c3.getLoadName());
Assert.assertEquals("c4 track", "Chelmsford Yard 3", c4.getTrackName());
Assert.assertEquals("c4 load", "E", c4.getLoadName());
Assert.assertEquals("c5 track", "Chelmsford Freight 2", c5.getTrackName());
Assert.assertEquals("c5 load", "Tin", c5.getLoadName());
Assert.assertEquals("c6 track", "Chelmsford Yard 3", c6.getTrackName());
Assert.assertEquals("c6 load", "L", c6.getLoadName());
Assert.assertEquals("c7 track", "Chelmsford Freight 4", c7.getTrackName());
Assert.assertEquals("c7 load", "L", c7.getLoadName());
Assert.assertEquals("c8 track", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load", "E", c8.getLoadName());
Assert.assertEquals("c9 track", "Chelmsford Freight 1", c9.getTrackName());
Assert.assertEquals("c9 load", "Scrap", c9.getLoadName());
Assert.assertEquals("c10 track", "Chelmsford Freight 4", c10.getTrackName());
Assert.assertEquals("c10 load", "E", c10.getLoadName());
Assert.assertEquals("c11 track", "Chelmsford Freight 4", c11.getTrackName());
Assert.assertEquals("c11 load", "E", c11.getLoadName());
Assert.assertEquals("c12 track", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load", "E", c12.getLoadName());
Assert.assertEquals("c13 track", "Chelmsford Freight 2", c13.getTrackName());
Assert.assertEquals("c13 load", "Tin", c13.getLoadName());
// create a route to staging to test remove schedule load
// Create route with 2 location
Route rte2;
rte2 = rmanager.newRoute("Chelmsford to Staging");
RouteLocation r2rl1 = rte2.addLocation(loc2);
r2rl1.setTrainDirection(RouteLocation.EAST);
r2rl1.setMaxCarMoves(12);
// set the train icon coordinates
r2rl1.setTrainIconX(125);
r2rl1.setTrainIconY(75);
RouteLocation r2rl3 = rte2.addLocation(loc3);
r2rl3.setTrainDirection(RouteLocation.EAST);
r2rl3.setMaxCarMoves(12);
// set the train icon coordinates
r2rl3.setTrainIconX(175);
r2rl3.setTrainIconY(75);
train1.setRoute(rte2);
train1.setName("Chelmsford to Bedford");
train1.build();
// move and terminate train
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track to staging", "Bedford Yard 1", c1.getTrackName());
Assert.assertEquals("c1 load to staging", "E", c1.getLoadName());
Assert.assertEquals("c2 track to staging", "Bedford Yard 1", c2.getTrackName());
Assert.assertEquals("c2 load to staging", "L", c2.getLoadName());
Assert.assertEquals("c3 track to staging", "Bedford Yard 1", c3.getTrackName());
Assert.assertEquals("c3 load to staging", "L", c3.getLoadName());
Assert.assertEquals("c4 track to staging", "Bedford Yard 1", c4.getTrackName());
Assert.assertEquals("c4 load to staging", "E", c4.getLoadName());
Assert.assertEquals("c5 track to staging", "Bedford Yard 1", c5.getTrackName());
Assert.assertEquals("c5 load to staging", "E", c5.getLoadName());
Assert.assertEquals("c6 track to staging", "Bedford Yard 1", c6.getTrackName());
Assert.assertEquals("c6 load to staging", "L", c6.getLoadName());
Assert.assertEquals("c7 track to staging", "Bedford Yard 1", c7.getTrackName());
Assert.assertEquals("c7 load to staging", "L", c7.getLoadName());
Assert.assertEquals("c8 track to staging", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load to staging", "E", c8.getLoadName());
Assert.assertEquals("c9 track to staging", "Bedford Yard 1", c9.getTrackName());
Assert.assertEquals("c9 load to staging", "E", c9.getLoadName());
Assert.assertEquals("c10 track to staging", "Bedford Yard 1", c10.getTrackName());
Assert.assertEquals("c10 load to staging", "E", c10.getLoadName());
Assert.assertEquals("c11 track to staging", "Bedford Yard 1", c11.getTrackName());
Assert.assertEquals("c11 load to staging", "E", c11.getLoadName());
Assert.assertEquals("c12 track to staging", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load to staging", "E", c12.getLoadName());
Assert.assertEquals("c13 track to staging", "Bedford Yard 1", c13.getTrackName());
Assert.assertEquals("c13 load to staging", "E", c13.getLoadName());
// create a route from staging to test generate schedule load
// Create route with 3 locations
Route rte3;
rte3 = rmanager.newRoute("Staging to Chelmsford");
RouteLocation r3rl1 = rte3.addLocation(loc3);
r3rl1.setTrainDirection(RouteLocation.EAST);
// there are 11 cars departing staging
r3rl1.setMaxCarMoves(11);
// set the train icon coordinates
r3rl1.setTrainIconX(25);
r3rl1.setTrainIconY(100);
RouteLocation r3rl2 = rte3.addLocation(loc2);
r3rl2.setTrainDirection(RouteLocation.EAST);
r3rl2.setMaxCarMoves(12);
RouteLocation r3rl3 = rte3.addLocation(loc1);
r3rl3.setTrainDirection(RouteLocation.EAST);
r3rl3.setMaxCarMoves(12);
// set the train icon coordinates
r3rl3.setTrainIconX(75);
r3rl3.setTrainIconY(100);
loc3trk1.setRemoveCustomLoadsEnabled(false);
// generate schedule loads
loc3trk1.setAddCustomLoadsEnabled(true);
// request these loads from staging
sch1Item1.setReceiveLoadName("Metal 1");
sch1Item2.setReceiveLoadName("Metal 2");
sch1Item3.setReceiveLoadName("Metal 3");
// Allows c13 which is part of a kernel to get a new load
CarLoads.instance().addName("Gon", "Metal 3");
train1.setRoute(rte3);
train1.setName("BCW");
train1.build();
Assert.assertEquals("Train Bedford Chelmsford Westford build status", true, train1.isBuilt());
Assert.assertEquals("c1 load from staging", "E", c1.getLoadName());
Assert.assertEquals("c2 load from staging", "L", c2.getLoadName());
Assert.assertEquals("c3 load from staging", "L", c3.getLoadName());
Assert.assertEquals("c4 load from staging", "E", c4.getLoadName());
Assert.assertEquals("c5 load from staging", "Metal 3", c5.getLoadName());
Assert.assertEquals("c6 load from staging", "L", c6.getLoadName());
Assert.assertEquals("c7 load from staging", "L", c7.getLoadName());
Assert.assertEquals("c8 load from staging", "E", c8.getLoadName());
Assert.assertEquals("c9 load from staging", "Metal 2", c9.getLoadName());
Assert.assertEquals("c9 next load from staging", "Scrap", c9.getNextLoadName());
Assert.assertEquals("c10 load from staging", "E", c10.getLoadName());
Assert.assertEquals("c11 load from staging", "E", c11.getLoadName());
Assert.assertEquals("c13 load from staging", "Metal 3", c13.getLoadName());
// move and terminate train
train1.move();
train1.move();
train1.move();
train1.move();
Assert.assertEquals("c1 track from staging terminated", "Westford Yard 1", c1.getTrackName());
Assert.assertEquals("c1 load from staging terminated", "E", c1.getLoadName());
Assert.assertEquals("c2 track from staging terminated", "Westford Yard 2", c2.getTrackName());
Assert.assertEquals("c2 load from staging terminated", "L", c2.getLoadName());
Assert.assertEquals("c3 track from staging terminated", "Westford Yard 1", c3.getTrackName());
Assert.assertEquals("c3 load from staging terminated", "L", c3.getLoadName());
Assert.assertEquals("c4 track from staging terminated", "Westford Express 4", c4.getTrackName());
Assert.assertEquals("c4 load from staging terminated", "L", c4.getLoadName());
Assert.assertEquals("c5 track from staging terminated", "Chelmsford Freight 2", c5.getTrackName());
Assert.assertEquals("c5 load from staging terminated", "Tin", c5.getLoadName());
Assert.assertEquals("c6 track from staging terminated", "Westford Express 3", c6.getTrackName());
Assert.assertEquals("c6 load from staging terminated", "E", c6.getLoadName());
Assert.assertEquals("c7 track from staging terminated", "Westford Yard 2", c7.getTrackName());
Assert.assertEquals("c7 load from staging terminated", "L", c7.getLoadName());
Assert.assertEquals("c8 track from staging terminated", "Westford Yard 2", c8.getTrackName());
Assert.assertEquals("c8 load from staging terminated", "E", c8.getLoadName());
Assert.assertEquals("c9 track from staging terminated", "Chelmsford Freight 2", c9.getTrackName());
Assert.assertEquals("c9 load from staging terminated", "Scrap", c9.getLoadName());
Assert.assertEquals("c10 track from staging terminated", "Chelmsford Freight 4", c10.getTrackName());
Assert.assertEquals("c10 load from staging terminated", "L", c10.getLoadName());
Assert.assertEquals("c11 track from staging terminated", "Westford Yard 1", c11.getTrackName());
Assert.assertEquals("c11 load from staging terminated", "E", c11.getLoadName());
Assert.assertEquals("c12 track from staging terminated", "Westford Yard 1", c12.getTrackName());
Assert.assertEquals("c12 load from staging terminated", "E", c12.getLoadName());
Assert.assertEquals("c13 track from staging terminated", "Chelmsford Freight 2", c13.getTrackName());
Assert.assertEquals("c13 load from staging terminated", "Tin", c13.getLoadName());
}
Aggregations