feat(marathon): add marathonArcInspector
This commit is contained in:
parent
f45f0027f0
commit
b7012ee892
1 changed files with 62 additions and 0 deletions
|
@ -0,0 +1,62 @@
|
||||||
|
package org.insa.graphs.algorithm.marathon;
|
||||||
|
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import org.insa.graphs.algorithm.AbstractInputData.Mode;
|
||||||
|
import org.insa.graphs.algorithm.ArcInspector;
|
||||||
|
import org.insa.graphs.model.AccessRestrictions.AccessMode;
|
||||||
|
import org.insa.graphs.model.AccessRestrictions.AccessRestriction;
|
||||||
|
import org.insa.graphs.model.Arc;
|
||||||
|
import org.insa.graphs.model.Path;
|
||||||
|
|
||||||
|
public class MarathonArcInspector implements ArcInspector{
|
||||||
|
static final int maxPedestrianSpeed = 10 ; // ie a 4:13 time
|
||||||
|
|
||||||
|
private Path path;
|
||||||
|
private Arc currentArc;
|
||||||
|
|
||||||
|
public MarathonArcInspector(Path path, Arc currentArc) {
|
||||||
|
this.path = path;
|
||||||
|
this.currentArc = currentArc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Checks whether the arc is accessible and whether it would create a cycle,
|
||||||
|
* leading to unhappy marathoners.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isAllowed(Arc arc) {
|
||||||
|
/*final boolean runnersCanAccess = arc.getRoadInformation().getAccessRestrictions()
|
||||||
|
.isAllowedForAny(AccessMode.FOOT, EnumSet.complementOf(EnumSet
|
||||||
|
.of(AccessRestriction.FORBIDDEN, AccessRestriction.PRIVATE)));*/
|
||||||
|
final boolean runnersCanAccess = true;
|
||||||
|
final boolean isCurrentArc = arc.getOrigin().equals(currentArc.getOrigin())
|
||||||
|
&& arc.getDestination().equals(currentArc.getDestination());
|
||||||
|
final boolean passesThroughOrigin = arc.getDestination().equals(path.getArcs().get(0).getOrigin());
|
||||||
|
|
||||||
|
boolean createsCycle = false;
|
||||||
|
for (Arc pathArc : this.path.getArcs()) {
|
||||||
|
if (arc.getDestination().equals(pathArc.getDestination())
|
||||||
|
&& !arc.getDestination().equals(currentArc.getDestination()))
|
||||||
|
createsCycle = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return runnersCanAccess && !isCurrentArc && !passesThroughOrigin && !createsCycle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getCost(Arc arc) {
|
||||||
|
return arc.getLength();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MarathonArcInspector";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mode getMode() {
|
||||||
|
return Mode.LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue