From: Stefan F. <ste...@us...> - 2010-05-20 19:57:10
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv22874/rails/algorithms Modified Files: NetworkTrain.java RevenueCalculator.java RevenueAdapter.java RevenueTrainRun.java RevenueBonus.java NetworkVertex.java NetworkGraphBuilder.java Log Message: Revenue Calculator support for 18AL and various other fixes Index: NetworkVertex.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkVertex.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** NetworkVertex.java 19 May 2010 20:14:13 -0000 1.12 --- NetworkVertex.java 20 May 2010 19:57:01 -0000 1.13 *************** *** 107,111 **** void addToRevenueCalculator(RevenueCalculator rc, int vertexId) { ! rc.setVertex(vertexId, major, minor); } --- 107,111 ---- void addToRevenueCalculator(RevenueCalculator rc, int vertexId) { ! rc.setVertex(vertexId, major, minor, sink); } *************** *** 259,263 **** // define value ! if (station.getType().equals(Station.OFF_MAP_AREA) || station.getValue() == -1) { value = hex.getCurrentOffBoardValue(phase); } else { --- 259,264 ---- // define value ! // if (station.getType().equals(Station.OFF_MAP_AREA) || station.getValue() == -1) { ! if (hex.hasOffBoardValues()) { value = hex.getCurrentOffBoardValue(phase); } else { *************** *** 334,338 **** if (addOldVertexAsHidden) hiddenVertices.add(vertex); hiddenVertices.addAll(edge.getHiddenVertexes()); ! NetworkEdge newEdge = new NetworkEdge(edge.getSource(), newVertex, edge.isGreedy(), edge.getDistance(), edge.getHiddenVertexes()); graph.addEdge(newEdge.getSource(), newVertex, newEdge); } --- 335,339 ---- if (addOldVertexAsHidden) hiddenVertices.add(vertex); hiddenVertices.addAll(edge.getHiddenVertexes()); ! NetworkEdge newEdge = new NetworkEdge(edge.getSource(), newVertex, edge.isGreedy(), edge.getDistance(), hiddenVertices); graph.addEdge(newEdge.getSource(), newVertex, newEdge); } Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** RevenueCalculator.java 18 May 2010 04:12:22 -0000 1.14 --- RevenueCalculator.java 20 May 2010 19:57:01 -0000 1.15 *************** *** 16,19 **** --- 16,20 ---- private final boolean[] vertexMajor; private final boolean[] vertexMinor; + private final boolean[] vertexSink; private final int[] vertexNbNeighbors; private final int[] vertexNbVisitSets; *************** *** 38,41 **** --- 39,43 ---- private final int[] trainMaxMajors; private final int[] trainMaxMinors; + private final int[] trainMaxBonuses; private final boolean[] trainIgnoreMinors; *************** *** 44,50 **** private final int[] trainMajors; private final int[] trainMinors; private final boolean[][] trainVisited; private final int[][] trainVertexStack; ! private final int[][] trainEdgeStack; private final int[] trainStackPos; private final int [] trainBottomPos; --- 46,53 ---- private final int[] trainMajors; private final int[] trainMinors; + private final int[] trainBonuses; // counts the number of bonuses received private final boolean[][] trainVisited; private final int[][] trainVertexStack; ! // private final int[][] trainEdgeStack; private final int[] trainStackPos; private final int [] trainBottomPos; *************** *** 114,117 **** --- 117,121 ---- vertexMajor = new boolean[nbVertexes]; vertexMinor = new boolean[nbVertexes]; + vertexSink = new boolean[nbVertexes]; vertexNbNeighbors = new int[nbVertexes]; vertexNbVisitSets = new int[nbVertexes]; *************** *** 128,131 **** --- 132,136 ---- trainMaxMajors = new int[nbTrains]; trainMaxMinors = new int[nbTrains]; + trainMaxBonuses = new int[nbTrains]; // only required for revenue prediction trainIgnoreMinors = new boolean[nbTrains]; *************** *** 133,140 **** trainMajors = new int[nbTrains]; trainMinors = new int[nbTrains]; trainVisited = new boolean[nbTrains][nbVertexes]; trainVertexStack = new int[nbTrains][nbVertexes + 1]; // increase necessary due to buttom train ! trainEdgeStack = new int[nbTrains][nbVertexes + 1]; trainStackPos = new int[nbTrains]; trainBottomPos = new int[nbTrains]; --- 138,146 ---- trainMajors = new int[nbTrains]; trainMinors = new int[nbTrains]; + trainBonuses = new int[nbTrains]; trainVisited = new boolean[nbTrains][nbVertexes]; trainVertexStack = new int[nbTrains][nbVertexes + 1]; // increase necessary due to buttom train ! // trainEdgeStack = new int[nbTrains][nbVertexes + 1]; trainStackPos = new int[nbTrains]; trainBottomPos = new int[nbTrains]; *************** *** 151,157 **** } ! void setVertex(int id, boolean major, boolean minor) { vertexMajor[id] = major; vertexMinor[id] = minor; // default neighbors && visit and bonus sets vertexNbNeighbors[id] = 0; --- 157,164 ---- } ! void setVertex(int id, boolean major, boolean minor, boolean sink) { vertexMajor[id] = major; vertexMinor[id] = minor; + vertexSink[id] = sink; // default neighbors && visit and bonus sets vertexNbNeighbors[id] = 0; *************** *** 187,190 **** --- 194,198 ---- trainMaxMajors[id] = majors; trainMaxMinors[id] = minors; + trainMaxBonuses[id] = 0; trainIgnoreMinors[id] = ignoreMinors; } *************** *** 249,253 **** bestRevenues[j] = cumulatedRevenues; } ! log.info(Arrays.toString(bestRevenues)); return bestRevenues; } --- 257,261 ---- bestRevenues[j] = cumulatedRevenues; } ! log.debug("Best Revenues = " + Arrays.toString(bestRevenues)); return bestRevenues; } *************** *** 258,279 **** maxMajorRevenues = new int[nbTrains][nbVertexes]; maxMinorRevenues = new int[nbTrains][nbVertexes]; for (int t=startTrain; t <= finalTrain; t++) { int[] majorValues = new int[nbVertexes]; int[] minorValues = new int[nbVertexes]; ! int[] bonusValues = new int[nbVertexes]; int major = 0, minor = 0, bonus = 0; for (int v=0; v < nbVertexes; v++) { if (vertexValueByTrain[v][t] == 0) continue; ! if (vertexMajor[v]) majorValues[major++] = vertexValueByTrain[v][t]; ! else if (vertexMinor[v]) minorValues[minor++] = vertexValueByTrain[v][t]; ! else bonusValues[bonus++] = vertexValueByTrain[v][t]; } maxMajorRevenues[t] = bestRevenues(majorValues, trainMaxMajors[t]); maxMinorRevenues[t] = bestRevenues(minorValues, trainMaxMinors[t]); ! maxCumulatedTrainRevenues[t] = maxMajorRevenues[t][trainMaxMajors[t]] + maxMinorRevenues[t][trainMaxMinors[t]]; } } --- 266,305 ---- maxMajorRevenues = new int[nbTrains][nbVertexes]; maxMinorRevenues = new int[nbTrains][nbVertexes]; + maxBonusRevenues = new int[nbTrains][nbVertexes + nbBonuses]; + int cumulatedRevenues = 0; for (int t=startTrain; t <= finalTrain; t++) { int[] majorValues = new int[nbVertexes]; int[] minorValues = new int[nbVertexes]; ! int[] bonusValues = new int[nbVertexes + nbBonuses]; int major = 0, minor = 0, bonus = 0; + // scan vertices for values for (int v=0; v < nbVertexes; v++) { if (vertexValueByTrain[v][t] == 0) continue; ! if (vertexMajor[v]) { majorValues[major++] = vertexValueByTrain[v][t]; ! } else if (vertexMinor[v]) { minorValues[minor++] = vertexValueByTrain[v][t]; ! } else { // define it as bonus bonusValues[bonus++] = vertexValueByTrain[v][t]; + } } + // add the (complex) bonuses + for (int b=0; b < nbBonuses; b++) { + if (bonusValue[b] <= 0 || !bonusActiveForTrain[b][t]) continue; + bonusValues[bonus++] = bonusValue[b]; + } + trainMaxBonuses[t] = bonus; + maxMajorRevenues[t] = bestRevenues(majorValues, trainMaxMajors[t]); maxMinorRevenues[t] = bestRevenues(minorValues, trainMaxMinors[t]); ! maxBonusRevenues[t] = bestRevenues(bonusValues, trainMaxBonuses[t]); ! cumulatedRevenues += maxMajorRevenues[t][trainMaxMajors[t]] + maxMinorRevenues[t][trainMaxMinors[t]] ! + maxBonusRevenues[t][trainMaxBonuses[t]]; ! maxCumulatedTrainRevenues[t] = cumulatedRevenues; } + log.info("maxMajorRevenues = " + Arrays.deepToString(maxMajorRevenues)); + log.info("maxMinorRevenues = " + Arrays.deepToString(maxMinorRevenues)); + log.info("maxBonusRevenues = " + Arrays.deepToString(maxBonusRevenues)); + log.info("maxCumulatedTrainRevenues = " + Arrays.toString(maxCumulatedTrainRevenues)); } *************** *** 313,316 **** --- 339,343 ---- maxCumulatedTrainRevenues[j] = cumulatedRevenues; } + log.info("maxCumulatedTrainRevenues = " + Arrays.toString(maxCumulatedTrainRevenues)); if (startTrain == finalTrain - 1) return; *************** *** 326,329 **** --- 353,357 ---- maxCumulatedTrainRevenues[j] = currentBestValue; maxCumulatedTrainRevenues[j-1] = currentBestValue + maxSingleTrainRevenues[j-1]; + log.info("maxCumulatedTrainRevenues = " + Arrays.toString(maxCumulatedTrainRevenues)); } } *************** *** 361,364 **** --- 389,393 ---- trainMajors[trainId] = trainMaxMajors[trainId]; trainMinors[trainId] = trainMaxMinors[trainId]; + trainBonuses[trainId] = trainMaxBonuses[trainId]; // initialize the positions *************** *** 393,396 **** --- 422,426 ---- // then try all edges of it + // for startVertices the sink property is ignored for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { int edgeId = vertexEdges[vertexId][j]; *************** *** 405,408 **** --- 435,439 ---- trainStartEdge[trainId] = j; // store start edge nextVertex(trainId, neighborId, edgeGreedy[edgeId]); + returnEdge(edgeId); } } *************** *** 430,440 **** log.debug("RC: runBottom " +trainId); trainBottomPos[trainId] = trainStackPos[trainId]; // store the stack position where bottom starts log.debug("RC: Restart at bottom at stack position " + trainBottomPos[trainId]); - // use startvertex - int vertexId = trainVertexStack[trainId][0]; - trainVertexStack[trainId][trainStackPos[trainId]++] = vertexId; // push to stack - for (int j = trainStartEdge[trainId] + 1; j < vertexNbNeighbors[vertexId]; j++) { int edgeId = vertexEdges[vertexId][j]; --- 461,476 ---- log.debug("RC: runBottom " +trainId); + // use startvertex, check if it is a sink + int vertexId = trainVertexStack[trainId][0]; + if (vertexSink[vertexId]) { + log.debug("RC: startvertex is sink, finished bottom of " + trainId); + return; + } + + // push to stack trainBottomPos[trainId] = trainStackPos[trainId]; // store the stack position where bottom starts + trainVertexStack[trainId][trainStackPos[trainId]++] = vertexId; log.debug("RC: Restart at bottom at stack position " + trainBottomPos[trainId]); for (int j = trainStartEdge[trainId] + 1; j < vertexNbNeighbors[vertexId]; j++) { int edgeId = vertexEdges[vertexId][j]; *************** *** 448,451 **** --- 484,488 ---- if (travelEdge(trainId, edgeId, true)) { nextVertex(trainId, neighborId, edgeGreedy[edgeId]); + returnEdge(edgeId); } } *************** *** 471,492 **** // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); ! returnEdge(trainId); return; } } ! // 2a. visit neighbors, if train has not terminated if (trainTerminated == Terminated.NotYet) { ! for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { ! int edgeId = vertexEdges[vertexId][j]; ! if (edgeUsed[edgeId]) continue; ! int neighborId = vertexNeighbors[vertexId][j]; ! log.debug("RC: Testing Neighbor Nr. " + j + " of " + vertexId + " is " + neighborId); ! if (trainVisited[trainId][neighborId]) { ! log.debug("RC: Hex already visited"); ! continue; ! } ! if (travelEdge(trainId, edgeId, previousGreedy)) { ! nextVertex(trainId, neighborId, edgeGreedy[edgeId]); } } --- 508,532 ---- // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); ! // returnEdge(trainId); return; } } ! // 2a. visit neighbors, if train has not terminated and vertex is not a sink if (trainTerminated == Terminated.NotYet) { ! if (!vertexSink[vertexId]) { ! for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { ! int edgeId = vertexEdges[vertexId][j]; ! if (edgeUsed[edgeId]) continue; ! int neighborId = vertexNeighbors[vertexId][j]; ! log.debug("RC: Testing Neighbor Nr. " + j + " of " + vertexId + " is " + neighborId); ! if (trainVisited[trainId][neighborId]) { ! log.debug("RC: Hex already visited"); ! continue; ! } ! if (travelEdge(trainId, edgeId, previousGreedy)) { ! nextVertex(trainId, neighborId, edgeGreedy[edgeId]); ! returnEdge(edgeId); ! } } } *************** *** 503,507 **** // 4. then leave that vertex encounterVertex(trainId, vertexId, false); ! returnEdge(trainId); } --- 543,547 ---- // 4. then leave that vertex encounterVertex(trainId, vertexId, false); ! // returnEdge(trainId); } *************** *** 553,556 **** --- 593,597 ---- if (bonusTrainVertices[bonusId][trainId] == 0) { trainCurrentValue[trainId] += bonusValue[bonusId]; + if (bonusValue[bonusId] > 0) trainBonuses[trainId]--; log.debug("RC: Added bonus " + bonusId + " with value " + bonusValue[bonusId]); } *************** *** 558,561 **** --- 599,603 ---- if (bonusTrainVertices[bonusId][trainId] == 0) { trainCurrentValue[trainId] -= bonusValue[bonusId]; + if (bonusValue[bonusId] > 0) trainBonuses[trainId]++; log.debug("RC: Removed bonus " + bonusId + " with value " + bonusValue[bonusId]); } *************** *** 565,568 **** --- 607,611 ---- } + log.debug("RC: stationVertex = " + stationVertex); log.debug("RC: Count Visits = " + countVisits); return stationVertex; *************** *** 573,577 **** log.debug("RC: Travel edge id " + edgeId); edgeUsed[edgeId] = true; ! trainEdgeStack[trainId][trainStackPos[trainId]] = edgeId; countEdges++; nbEdgesTravelled++; log.debug("RC: Count Edges = " + countEdges); --- 616,620 ---- log.debug("RC: Travel edge id " + edgeId); edgeUsed[edgeId] = true; ! // trainEdgeStack[trainId][trainStackPos[trainId]] = edgeId; countEdges++; nbEdgesTravelled++; log.debug("RC: Count Edges = " + countEdges); *************** *** 583,601 **** } ! private void returnEdge(int trainId) { ! int stackPos = trainStackPos[trainId]; ! log.debug("RC: Tries to clear edge at stack position " + stackPos + " of train " + trainId); ! ! if (stackPos == 0) { ! log.debug("RC: Position zero has not to be cleared"); ! return; ! } ! ! if (stackPos == trainBottomPos[trainId]) { ! log.debug("RC: Replace start Vertex for bottom position"); ! } ! ! int edgeId = trainEdgeStack[trainId][stackPos]; ! if (edgeUsed[edgeId]) { edgeUsed[edgeId] = false; --- 626,630 ---- } ! private void returnEdge(int edgeId) { if (edgeUsed[edgeId]) { edgeUsed[edgeId] = false; *************** *** 604,608 **** log.debug("RC: Count Edges = " + countEdges); } else { ! log.debug ("RC: Error return edge id used: " + edgeId); } } --- 633,637 ---- log.debug("RC: Count Edges = " + countEdges); } else { ! log.debug("RC: Error return edge id used: " + edgeId); } } *************** *** 696,699 **** --- 725,732 ---- } } + // add potential bonuses + if (trainBonuses[trainId] != 0) { + trainValue += maxBonusRevenues[trainId][trainBonuses[trainId]]; + } log.debug("RC: Current train has predicted value of " + trainValue); Index: RevenueBonus.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueBonus.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RevenueBonus.java 14 May 2010 15:19:57 -0000 1.2 --- RevenueBonus.java 20 May 2010 19:57:01 -0000 1.3 *************** *** 1,4 **** --- 1,5 ---- package rails.algorithms; + import java.util.Collection; import java.util.List; import java.util.ArrayList; *************** *** 7,10 **** --- 8,12 ---- import rails.game.PhaseI; + import rails.game.TrainI; import rails.game.TrainTypeI; *************** *** 23,26 **** --- 25,29 ---- private List<NetworkVertex> vertices; private List<TrainTypeI> trainTypes; + private List<TrainI> trains; private List<PhaseI> phases; *************** *** 31,34 **** --- 34,38 ---- vertices = new ArrayList<NetworkVertex>(); trainTypes = new ArrayList<TrainTypeI>(); + trains = new ArrayList<TrainI>(); phases = new ArrayList<PhaseI>(); } *************** *** 37,40 **** --- 41,48 ---- vertices.add(vertex); } + + public void addVertices(Collection<NetworkVertex> vertices) { + this.vertices.addAll(vertices); + } public void addTrainType(TrainTypeI trainType) { *************** *** 42,45 **** --- 50,57 ---- } + public void addTrain(TrainI train) { + trains.add(train); + } + public void addPhase(PhaseI phase) { phases.add(phase); *************** *** 62,65 **** --- 74,81 ---- } + public List<TrainI> getTrains() { + return trains; + } + public List<PhaseI> getPhases() { return phases; *************** *** 82,86 **** boolean[] trainsArray = new boolean[trains.size()]; for (int j=0; j < trains.size(); j++) { ! trainsArray[j] = checkConditions(trains.get(j).getRailsTrainType(), phase); } --- 98,102 ---- boolean[] trainsArray = new boolean[trains.size()]; for (int j=0; j < trains.size(); j++) { ! trainsArray[j] = checkConditions(trains.get(j).getRailsTrain(), phase); } *************** *** 92,101 **** } ! public boolean checkSimpleBonus(NetworkVertex vertex, TrainTypeI trainType, PhaseI phase) { ! return (isSimpleBonus() && vertices.contains(vertex) && checkConditions(trainType, phase)); } ! public boolean checkComplexBonus(List<NetworkVertex> visitVertices, TrainTypeI trainType, PhaseI phase) { ! boolean result = !isSimpleBonus() && checkConditions(trainType, phase); if (result) { for (NetworkVertex vertex:vertices) { --- 108,117 ---- } ! public boolean checkSimpleBonus(NetworkVertex vertex, TrainI train, PhaseI phase) { ! return (isSimpleBonus() && vertices.contains(vertex) && checkConditions(train, phase)); } ! public boolean checkComplexBonus(List<NetworkVertex> visitVertices, TrainI train, PhaseI phase) { ! boolean result = !isSimpleBonus() && checkConditions(train, phase); if (result) { for (NetworkVertex vertex:vertices) { *************** *** 109,121 **** } ! public boolean checkConditions(TrainTypeI trainType, PhaseI phase) { boolean result = true; // check trainTypes if (!trainTypes.isEmpty()) { ! if (trainType == null) { result = false; } else { ! result = result && trainTypes.contains(trainType); } } --- 125,146 ---- } ! public boolean checkConditions(TrainI train, PhaseI phase) { boolean result = true; + // check train + if (!trains.isEmpty()) { + if (train == null) { + result = false; + } else { + result = result && trains.contains(train); + } + } + // check trainTypes if (!trainTypes.isEmpty()) { ! if (train == null) { result = false; } else { ! result = result && trainTypes.contains(train.getType()); } } Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** RevenueAdapter.java 19 May 2010 20:14:13 -0000 1.16 --- RevenueAdapter.java 20 May 2010 19:57:01 -0000 1.17 *************** *** 335,355 **** } ! // set neighbors ! if (!v.isSink()) { ! List<NetworkVertex> neighbors = Graphs.neighborListOf(rcGraph, v); ! int j=0, neighborsArray[] = new int[neighbors.size()]; ! for (NetworkVertex n:neighbors){ ! neighborsArray[j++] = rcVertices.indexOf(n); ! } ! // sort by value orderboolean activatePrediction ! Arrays.sort(neighborsArray, 0, j); ! // define according edges ! int[] edgesArray = new int[j]; ! for (int e=0; e < j; e++) { ! NetworkVertex n = rcVertices.get(neighborsArray[e]); ! edgesArray[e] = rcEdges.indexOf(rcGraph.getEdge(v, n)); ! } ! rc.setVertexNeighbors(id, neighborsArray, edgesArray); } } --- 335,357 ---- } ! // set neighbors, now regardless of sink property ! // this is covered by the vertex attribute ! // and required for startvertices that are sinks themselves ! // if (!v.isSink()) { ! List<NetworkVertex> neighbors = Graphs.neighborListOf(rcGraph, v); ! int j=0, neighborsArray[] = new int[neighbors.size()]; ! for (NetworkVertex n:neighbors){ ! neighborsArray[j++] = rcVertices.indexOf(n); } + // sort by value orderboolean activatePrediction + Arrays.sort(neighborsArray, 0, j); + // define according edges + int[] edgesArray = new int[j]; + for (int e=0; e < j; e++) { + NetworkVertex n = rcVertices.get(neighborsArray[e]); + edgesArray[e] = rcEdges.indexOf(rcGraph.getEdge(v, n)); + } + rc.setVertexNeighbors(id, neighborsArray, edgesArray); + // } } *************** *** 403,407 **** // add potential revenueBonuses for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrainType(), phase)) { value += bonus.getValue(); } --- 405,409 ---- // add potential revenueBonuses for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrain(), phase)) { value += bonus.getValue(); } *************** *** 419,423 **** // add potential revenueBonuses for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrainType(), phase)) { s.append("+" + bonus.getValue()); } --- 421,425 ---- // add potential revenueBonuses for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrain(), phase)) { s.append("+" + bonus.getValue()); } Index: NetworkGraphBuilder.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkGraphBuilder.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** NetworkGraphBuilder.java 14 May 2010 15:19:57 -0000 1.10 --- NetworkGraphBuilder.java 20 May 2010 19:57:01 -0000 1.11 *************** *** 169,172 **** --- 169,174 ---- for (NetworkVertex vertex:tokenVertexes){ + // allow to leave tokenVertices even if those are sinks + boolean storeSink = vertex.isSink(); vertex.setSink(false); vertexes.add(vertex); // add connection to graph *************** *** 176,179 **** --- 178,183 ---- for (;iterator.hasNext();) vertexes.add(iterator.next()); + // restore sink property + vertex.setSink(storeSink); } Index: RevenueTrainRun.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueTrainRun.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RevenueTrainRun.java 19 May 2010 20:14:13 -0000 1.3 --- RevenueTrainRun.java 20 May 2010 19:57:01 -0000 1.4 *************** *** 8,12 **** import org.apache.log4j.Logger; - import rails.game.MapHex; import rails.ui.swing.hexmap.HexMap; --- 8,11 ---- *************** *** 51,55 **** // check revenueBonuses (complex) for (RevenueBonus bonus:revenueAdapter.getRevenueBonuses()) { ! if (bonus.checkComplexBonus(vertices, train.getRailsTrainType(), revenueAdapter.getPhase())) { value += bonus.getValue(); } --- 50,54 ---- // check revenueBonuses (complex) for (RevenueBonus bonus:revenueAdapter.getRevenueBonuses()) { ! if (bonus.checkComplexBonus(vertices, train.getRailsTrain(), revenueAdapter.getPhase())) { value += bonus.getValue(); } *************** *** 81,99 **** int initLength = runPrettyPrint.length(); int multiple = runPrettyPrint.length() / PRETTY_PRINT_LENGTH; ! MapHex currentHex = null; NetworkVertex startVertex = null; for (NetworkVertex vertex:vertices) { if (startVertex == null) { ! currentHex = vertex.getHex(); startVertex = vertex; runPrettyPrint.append(prettyPrintHexName(vertex) + "("); } else if (startVertex == vertex) { ! currentHex = vertex.getHex(); runPrettyPrint.append(") / "); multiple = prettyPrintNewLine(runPrettyPrint, multiple, initLength); runPrettyPrint.append(prettyPrintHexName(vertex) + "(0"); continue; ! } else if (vertex.getHex() != currentHex) { ! currentHex = vertex.getHex(); runPrettyPrint.append("), "); multiple = prettyPrintNewLine(runPrettyPrint, multiple, initLength); --- 80,98 ---- int initLength = runPrettyPrint.length(); int multiple = runPrettyPrint.length() / PRETTY_PRINT_LENGTH; ! String currentHexName = null; NetworkVertex startVertex = null; for (NetworkVertex vertex:vertices) { if (startVertex == null) { ! currentHexName = prettyPrintHexName(vertex); startVertex = vertex; runPrettyPrint.append(prettyPrintHexName(vertex) + "("); } else if (startVertex == vertex) { ! currentHexName = prettyPrintHexName(vertex); runPrettyPrint.append(") / "); multiple = prettyPrintNewLine(runPrettyPrint, multiple, initLength); runPrettyPrint.append(prettyPrintHexName(vertex) + "(0"); continue; ! } else if (!currentHexName.equals(prettyPrintHexName(vertex))) { ! currentHexName = prettyPrintHexName(vertex); runPrettyPrint.append("), "); multiple = prettyPrintNewLine(runPrettyPrint, multiple, initLength); *************** *** 105,113 **** runPrettyPrint.append(revenueAdapter.getVertexValueAsString(vertex, train, revenueAdapter.getPhase())); } else { ! runPrettyPrint.append(currentHex.getOrientationName(vertex.getSide())); } } ! if (currentHex != null) { runPrettyPrint.append(")"); } --- 104,112 ---- runPrettyPrint.append(revenueAdapter.getVertexValueAsString(vertex, train, revenueAdapter.getPhase())); } else { ! runPrettyPrint.append(vertex.getHex().getOrientationName(vertex.getSide())); } } ! if (currentHexName != null) { runPrettyPrint.append(")"); } *************** *** 115,119 **** // check revenueBonuses (complex) for (RevenueBonus bonus:revenueAdapter.getRevenueBonuses()) { ! if (bonus.checkComplexBonus(vertices, train.getRailsTrainType(), revenueAdapter.getPhase())) { runPrettyPrint.append(" + "); runPrettyPrint.append(bonus.getName() + "(" + bonus.getValue() + ")"); --- 114,118 ---- // check revenueBonuses (complex) for (RevenueBonus bonus:revenueAdapter.getRevenueBonuses()) { ! if (bonus.checkComplexBonus(vertices, train.getRailsTrain(), revenueAdapter.getPhase())) { runPrettyPrint.append(" + "); runPrettyPrint.append(bonus.getName() + "(" + bonus.getValue() + ")"); Index: NetworkTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkTrain.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** NetworkTrain.java 18 May 2010 21:36:12 -0000 1.7 --- NetworkTrain.java 20 May 2010 19:57:01 -0000 1.8 *************** *** 17,25 **** private final int multiplyMinors; private final String trainName; ! private final TrainTypeI railsTrainType; NetworkTrain(int majors, int minors, boolean ignoreMinors, ! int multiplyMajors, int multiplyMinors, String trainName, ! TrainTypeI trainType) { this.majors = majors; this.minors = minors; --- 17,25 ---- private final int multiplyMinors; private final String trainName; ! private final TrainI railsTrain; ! NetworkTrain(int majors, int minors, boolean ignoreMinors, ! int multiplyMajors, int multiplyMinors, String trainName, TrainI train) { this.majors = majors; this.minors = minors; *************** *** 28,32 **** this.multiplyMinors = multiplyMinors; this.trainName = trainName; ! this.railsTrainType = trainType; log.info("Created NetworkTrain " + this.toString() + " / " + this.attributes()); } --- 28,32 ---- this.multiplyMinors = multiplyMinors; this.trainName = trainName; ! this.railsTrain = train; log.info("Created NetworkTrain " + this.toString() + " / " + this.attributes()); } *************** *** 45,49 **** } String trainName = railsTrain.getName(); - TrainTypeI trainType = railsTrain.getType(); if (majors == -1) { --- 45,48 ---- *************** *** 51,55 **** } else { return new NetworkTrain(majors, minors, ignoreMinors, multiplyMajors, multiplyMinors, ! trainName, trainType); } } --- 50,54 ---- } else { return new NetworkTrain(majors, minors, ignoreMinors, multiplyMajors, multiplyMinors, ! trainName, railsTrain); } } *************** *** 116,122 **** } ! TrainTypeI getRailsTrainType() { ! return railsTrainType; } public String attributes() { --- 115,126 ---- } ! public TrainI getRailsTrain() { ! return railsTrain; } + + public TrainTypeI getRailsTrainType() { + return railsTrain.getType(); + } + public String attributes() { |