Commit f9d8a594 authored by Jakob Schöttl's avatar Jakob Schöttl
Browse files

Change impl for only one interim target per compartment

parent a748c5ab
......@@ -80,7 +80,7 @@ public class SeatingModel implements ActiveCallback, Model {
log.debug("Assigning compartment target to pedestrian " + p.getId());
final int entranceAreaIndex = trainModel.getEntranceAreaIndexForPerson(p);
final Compartment compartment = chooseCompartment(p, entranceAreaIndex);
p.addTarget(compartment.getInterimTargetCloserTo(entranceAreaIndex));
p.addTarget(compartment.getInterimTarget());
}
private void assignSeatTarget(Pedestrian p) {
......
......@@ -67,29 +67,11 @@ public class Compartment {
return seatGroups;
}
public Target getInterimTargetCloserTo(int entranceAreaIndex) {
public Target getInterimTarget() {
// entrance areas: 0 1 2 3
// compartments: 0 1 2 3 4
// interim targets: 0 123 456 489 .
trainModel.checkEntranceAreaIndexRange(entranceAreaIndex);
final List<Target> interimTargets = trainModel.getInterimDestinations();
if (isFirstHalfCompartment()) {
return interimTargets.get(0);
} else if (isLastHalfCompartment()) {
return interimTargets.get(interimTargets.size() - 1);
}
final int interimTargetStartIndex = index * 3 - 2;
if (index <= entranceAreaIndex) {
// use interim target with higher number
return interimTargets.get(interimTargetStartIndex + 2);
} else {
// use interim target with smaller number
return interimTargets.get(interimTargetStartIndex);
}
// interim targets: 0 1 2 3 4
return trainModel.getInterimDestinations().get(index);
}
private boolean isLastHalfCompartment() {
......
......@@ -275,8 +275,7 @@ public class TrainModel {
if (index == -1) {
throw new IllegalArgumentException("Given target is not an interim target.");
}
System.out.println("index of interim target: " + index + "; index of compartment: " + (index + 2) / 3);
return getCompartment((index + 2) / 3);
return getCompartment(index);
}
void checkEntranceAreaIndexRange(int entranceAreaIndex) {
......
--number-entrance-areas=12
--door-source-distance=0.5
--block-ends --block-exits
--interim-destinations
--random-seed=0
--number-sitting-persons=10
--stop=10,top,10
--stop=20,bottom,20
--stop=30,top,10
--stop=30,bottom,10
--train-geometry=org.vadere.state.scenario.Et423Geometry
--output-file=/tmp/test-train-topography.json
\ No newline at end of file
......@@ -21,7 +21,7 @@ public class TestTopographyAndModelBuilder {
public static final int nEntranceAreas = 12;
public static final int nCompartments = nEntranceAreas + 1; // includes 2 half-compartments
public static final int nInterimDestinations = nCompartments * 3 - 4; // includes 2 targets from half-compartments
public static final int nInterimDestinations = nCompartments; // includes 2 targets from half-compartments
public static final int nSeatGroups = nCompartments * 4 - 4;
public static final int nSeats = nSeatGroups * 4;
public static final int nSeatRows = nCompartments * 4 - 4;
......
......@@ -75,7 +75,7 @@ public class TestTrainModel {
@Test
public void testCertainInterimTarget() {
for (Target t : trainModel.getInterimDestinations())
if (t.getId() == 133)
if (t.getId() == 205) // an example for an interim target
return;
fail("Interim target with id not found.");
}
......@@ -146,10 +146,8 @@ public class TestTrainModel {
assertEquals(trainModel.getSeats().get(0), c.getSeatGroups().get(0).getSeat(0));
for (int i = 0; i < nEntranceAreas; i++) {
assertEquals(trainModel.getInterimDestinations().get(0),
c.getInterimTargetCloserTo(i));
}
assertEquals(trainModel.getInterimDestinations().get(0),
c.getInterimTarget());
}
@Test
......@@ -164,11 +162,7 @@ public class TestTrainModel {
assertTrue(c.getSeatGroups().get(0).getSeat(0) == trainModel.getSeats().get(8));
assertEquals(trainModel.getInterimDestinations().get(1), c.getInterimTargetCloserTo(0));
for (int i = 1; i < nEntranceAreas; i++) {
assertEquals(trainModel.getInterimDestinations().get(3),
c.getInterimTargetCloserTo(i));
}
assertEquals(trainModel.getInterimDestinations().get(1), c.getInterimTarget());
}
@Test
......@@ -181,10 +175,8 @@ public class TestTrainModel {
assertTrue(c.getSeatGroups().get(1).getSeat(3) == trainModel.getSeats().get(nSeats - 1));
for (int i = 0; i < nEntranceAreas; i++) {
assertEquals(trainModel.getInterimDestinations().get(nInterimDestinations - 1),
c.getInterimTargetCloserTo(i));
}
assertEquals(trainModel.getInterimDestinations().get(nInterimDestinations - 1),
c.getInterimTarget());
}
@Test
......@@ -220,11 +212,11 @@ public class TestTrainModel {
assertEquals(trainModel.getCompartment(0), getCompartmentByInterimTargetIndex(0));
assertEquals(trainModel.getCompartment(1), getCompartmentByInterimTargetIndex(1));
assertEquals(trainModel.getCompartment(1), getCompartmentByInterimTargetIndex(3));
assertEquals(trainModel.getCompartment(2), getCompartmentByInterimTargetIndex(4));
assertEquals(trainModel.getCompartment(2), getCompartmentByInterimTargetIndex(2));
assertEquals(trainModel.getCompartment(3), getCompartmentByInterimTargetIndex(3));
assertEquals(trainModel.getCompartment(nCompartments - 3), getCompartmentByInterimTargetIndex(nInterimDestinations - 5));
assertEquals(trainModel.getCompartment(nCompartments - 2), getCompartmentByInterimTargetIndex(nInterimDestinations - 4));
assertEquals(trainModel.getCompartment(nCompartments - 4), getCompartmentByInterimTargetIndex(nInterimDestinations - 4));
assertEquals(trainModel.getCompartment(nCompartments - 3), getCompartmentByInterimTargetIndex(nInterimDestinations - 3));
assertEquals(trainModel.getCompartment(nCompartments - 2), getCompartmentByInterimTargetIndex(nInterimDestinations - 2));
assertEquals(trainModel.getCompartment(nCompartments - 1), getCompartmentByInterimTargetIndex(nInterimDestinations - 1));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment