overhauled route search algorithm:

now using breadth-first search instead of depth-first search
This commit is contained in:
Stephan Richter
2021-04-01 09:55:27 +02:00
parent 2967e3b762
commit db9fed1642
11 changed files with 250 additions and 129 deletions

View File

@@ -27,7 +27,6 @@ import de.srsoftware.web4rail.tags.Window;
import de.srsoftware.web4rail.threads.DelayedExecution;
public class Contact extends Tile{
private static Logger LOG = LoggerFactory.getLogger(Contact.class);
private static final String ADDRESS = "address";
private static final HashMap<Integer, Contact> contactsByAddr = new HashMap<Integer, Contact>();
private boolean state = false;

View File

@@ -52,7 +52,7 @@ public abstract class Turnout extends Tile implements Device{
@Override
public Object click(boolean shift) throws IOException {
LOG.debug(getClass().getSimpleName()+".click()");
if (!shift) init();
init();
return super.click(shift);
}
@@ -159,9 +159,13 @@ public abstract class Turnout extends Tile implements Device{
return state;
}
public Reply state(State newState) {
public Reply state(State newState,boolean shift) {
Train lockingTrain = lockingTrain();
if (isSet(lockingTrain) && newState != state) return new Reply(415, t("{} locked by {}!",this,lockingTrain));
if (isSet(lockingTrain)) {
if (newState != state && !shift) return new Reply(415, t("{} locked by {}!",this,lockingTrain));
// shift allows to switch locked turnouts...
} else if (shift) return new Reply(200,"OK"); // shift on a non-locked turnout skips the switch process
if (address == 0) {
sleep(300);
state = newState;

View File

@@ -15,7 +15,7 @@ public abstract class TurnoutL extends Turnout {
@Override
public Object click(boolean shift) throws IOException {
Object o = super.click(shift);
if (!shift) state(state == State.STRAIGHT ? State.LEFT : State.STRAIGHT);
state(state == State.STRAIGHT ? State.LEFT : State.STRAIGHT,shift);
return o;
}

View File

@@ -15,13 +15,12 @@ public abstract class TurnoutR extends Turnout {
@Override
public Object click(boolean shift) throws IOException {
Object o = super.click(shift);
if (!shift) state(state == State.STRAIGHT ? State.RIGHT : State.STRAIGHT);
state(state == State.STRAIGHT ? State.RIGHT : State.STRAIGHT,shift);
return o;
}
@Override
public String commandFor(State newState) {
switch (newState) {
case RIGHT:
return "SET {} GA "+address+" "+portB+" 1 "+delay;