You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(3) |
Nov
(46) |
Dec
(57) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
(51) |
Feb
(10) |
Mar
|
Apr
|
May
(14) |
Jun
|
Jul
(13) |
Aug
(30) |
Sep
(83) |
Oct
(56) |
Nov
(148) |
Dec
(107) |
2010 |
Jan
(260) |
Feb
(164) |
Mar
(183) |
Apr
(99) |
May
(160) |
Jun
(40) |
Jul
(33) |
Aug
(48) |
Sep
(22) |
Oct
(24) |
Nov
(1) |
Dec
(12) |
2011 |
Jan
(6) |
Feb
(15) |
Mar
(13) |
Apr
(37) |
May
(27) |
Jun
(29) |
Jul
(33) |
Aug
(20) |
Sep
(17) |
Oct
(20) |
Nov
(33) |
Dec
(17) |
2012 |
Jan
(39) |
Feb
(38) |
Mar
(20) |
Apr
(21) |
May
(17) |
Jun
(22) |
Jul
(16) |
Aug
(3) |
Sep
(9) |
Oct
(10) |
Nov
|
Dec
|
From: Erik V. <ev...@us...> - 2010-05-15 22:44:54
|
Update of /cvsroot/rails/18xx/rails/util In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26563/rails/util Modified Files: Config.java Log Message: Enable custom route colours Index: Config.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/util/Config.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Config.java 16 Jan 2010 14:09:33 -0000 1.11 --- Config.java 15 May 2010 22:44:46 -0000 1.12 *************** *** 49,52 **** --- 49,62 ---- } + public static String get(String key, String defaultValue) { + + if (prop.isEmpty() || !loaded) { + load(); + } + if (prop.containsKey(key)) return prop.getProperty(key).trim(); + + return defaultValue; + } + private static void load() { |
From: Erik V. <ev...@us...> - 2010-05-15 22:44:54
|
Update of /cvsroot/rails/18xx In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26563 Modified Files: my.properties Log Message: Enable custom route colours Index: my.properties =================================================================== RCS file: /cvsroot/rails/18xx/my.properties,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** my.properties 20 Apr 2010 20:18:17 -0000 1.15 --- my.properties 15 May 2010 22:44:46 -0000 1.16 *************** *** 107,110 **** --- 107,120 ---- #or.number_format=simple + + ### Colours + ## Train route colours + # As in the XML files, colours can be specified as either hexadecimal RRGGBB, + # or as decimal RR,GG,BB + #route.colour.1=FF0000 + #route.colour.2=00FF00 + #route.colour.3=0000FF + #route.colour.4=808000 + ####################### Log4J properties ############################## # For information on how to customise log4j logging, see for instance |
From: Erik V. <ev...@us...> - 2010-05-15 22:44:54
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv26563/rails/ui/swing/hexmap Modified Files: HexMap.java Log Message: Enable custom route colours Index: HexMap.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/HexMap.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** HexMap.java 29 Apr 2010 19:47:32 -0000 1.25 --- HexMap.java 15 May 2010 22:44:46 -0000 1.26 *************** *** 16,19 **** --- 16,20 ---- import rails.ui.swing.GameUIManager; import rails.ui.swing.ORUIManager; + import rails.util.*; /** *************** *** 69,77 **** /** list of generalpath elements to indicate train runs */ protected List<GeneralPath> trainPaths; ! protected Color[] trainColors = new Color[]{Color.CYAN, Color.PINK, Color.ORANGE, Color.GRAY}; protected int strokeWidth = 5; protected int strokeCap = BasicStroke.CAP_ROUND; protected int strokeJoin = BasicStroke.JOIN_BEVEL; public void init(ORUIManager orUIManager, MapManager mapManager) { this.orUIManager = orUIManager; --- 70,95 ---- /** list of generalpath elements to indicate train runs */ protected List<GeneralPath> trainPaths; ! ! private static Color colour1, colour2, colour3, colour4; ! protected Color[] trainColors = new Color[4]; protected int strokeWidth = 5; protected int strokeCap = BasicStroke.CAP_ROUND; protected int strokeJoin = BasicStroke.JOIN_BEVEL; + static { + try { + colour1 = Util.parseColour(Config.get("route.colour.1", null)); + colour2 = Util.parseColour(Config.get("route.colour.2", null)); + colour3 = Util.parseColour(Config.get("route.colour.3", null)); + colour4 = Util.parseColour(Config.get("route.colour.4", null)); + } catch (ConfigurationException e) { + } finally { + if (colour1 == null) colour1 = Color.CYAN; + if (colour2 == null) colour2 = Color.PINK; + if (colour3 == null) colour3 = Color.ORANGE; + if (colour4 == null) colour4 = Color.GRAY; + } + } + public void init(ORUIManager orUIManager, MapManager mapManager) { this.orUIManager = orUIManager; *************** *** 86,89 **** --- 104,109 ---- maxCol = mapManager.getMaxCol(); setupHexes(); + + trainColors = new Color[]{colour1, colour2, colour3, colour4}; } |
From: Erik V. <ev...@us...> - 2010-05-15 19:05:49
|
Update of /cvsroot/rails/18xx/rails/ui/swing/hexmap In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30026/rails/ui/swing/hexmap Modified Files: GUITile.java Log Message: Fixed 1835 bug at buying the first 5-train. Fixed Hamburg tile orientation: can no longer rotate. Index: GUITile.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/hexmap/GUITile.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** GUITile.java 2 May 2010 20:18:31 -0000 1.24 --- GUITile.java 15 May 2010 19:05:39 -0000 1.25 *************** *** 81,84 **** --- 81,90 ---- boolean connected; + + int fixedRotation = getTile().getFixedOrientation(); + if (fixedRotation >= 0) { + setRotation (fixedRotation); + return true; + } /* Loop through all possible rotations */ |
From: Erik V. <ev...@us...> - 2010-05-15 19:05:49
|
Update of /cvsroot/rails/18xx/data/1835 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30026/data/1835 Modified Files: TileSet.xml Log Message: Fixed 1835 bug at buying the first 5-train. Fixed Hamburg tile orientation: can no longer rotate. Index: TileSet.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1835/TileSet.xml,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** TileSet.xml 14 May 2010 15:19:57 -0000 1.14 --- TileSet.xml 15 May 2010 19:05:40 -0000 1.15 *************** *** 190,194 **** <Tile id="219" quantity="2" /> <Tile id="220" quantity="1" /> ! <Tile id="221" quantity="1" > <RevenueBonus value="-10" name="Elbe"> <Vertex id="0"/> <Vertex id="2"/> </RevenueBonus> <RevenueBonus value="-10" name="Elbe"> <Vertex id="0"/> <Vertex id="3"/> </RevenueBonus> --- 190,194 ---- <Tile id="219" quantity="2" /> <Tile id="220" quantity="1" /> ! <Tile id="221" quantity="1" orientation="0"> <RevenueBonus value="-10" name="Elbe"> <Vertex id="0"/> <Vertex id="2"/> </RevenueBonus> <RevenueBonus value="-10" name="Elbe"> <Vertex id="0"/> <Vertex id="3"/> </RevenueBonus> |
From: Erik V. <ev...@us...> - 2010-05-15 19:05:49
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30026/rails/game Modified Files: TileI.java Tile.java Log Message: Fixed 1835 bug at buying the first 5-train. Fixed Hamburg tile orientation: can no longer rotate. Index: TileI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TileI.java,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** TileI.java 14 May 2010 15:19:57 -0000 1.19 --- TileI.java 15 May 2010 19:05:39 -0000 1.20 *************** *** 70,73 **** --- 70,74 ---- public int getQuantity(); + public int getFixedOrientation (); public List<RevenueBonusTemplate> getRevenueBonuses(); Index: Tile.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Tile.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Tile.java 14 May 2010 15:19:57 -0000 1.40 --- Tile.java 15 May 2010 19:05:39 -0000 1.41 *************** *** 32,36 **** private final List<Upgrade> upgrades = new ArrayList<Upgrade>(); // Contains // Upgrade instances ! private String upgradesString = ""; @SuppressWarnings("unchecked") private final List[] tracksPerSide = new ArrayList[6]; --- 32,36 ---- private final List<Upgrade> upgrades = new ArrayList<Upgrade>(); // Contains // Upgrade instances ! //private String upgradesString = ""; @SuppressWarnings("unchecked") private final List[] tracksPerSide = new ArrayList[6]; *************** *** 44,47 **** --- 44,49 ---- private boolean unlimited = false; private boolean allowsMultipleBasesOfOneCompany = false; + /** Fixed orientation; -1 if free to rotate */ + private int fixedOrientation = -1; public static final int UNLIMITED_TILES = -1; *************** *** 125,129 **** } colourNumber -= TILE_NUMBER_OFFSET; ! /* Stations */ List<Tag> stationTags = defTag.getChildren("Station"); --- 127,131 ---- } colourNumber -= TILE_NUMBER_OFFSET; ! /* Stations */ List<Tag> stationTags = defTag.getChildren("Station"); *************** *** 213,216 **** --- 215,220 ---- "AllowsMultipleBasesOfOneCompany"); + fixedOrientation = setTag.getAttributeAsInteger("orientation", fixedOrientation); + /* Upgrades */ List<Tag> upgradeTags = setTag.getChildren("Upgrade"); *************** *** 225,229 **** for (Tag upgradeTag : upgradeTags) { ids = upgradeTag.getAttributeAsString("id"); ! upgradesString = ids; // TEMPORARY List<Upgrade> newUpgrades = new ArrayList<Upgrade>(); --- 229,233 ---- for (Tag upgradeTag : upgradeTags) { ids = upgradeTag.getAttributeAsString("id"); ! //upgradesString = ids; // TEMPORARY List<Upgrade> newUpgrades = new ArrayList<Upgrade>(); *************** *** 493,496 **** --- 497,504 ---- return quantity; } + + public int getFixedOrientation () { + return fixedOrientation; + } public List<RevenueBonusTemplate> getRevenueBonuses() { |
From: Erik V. <ev...@us...> - 2010-05-15 19:05:49
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1835 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30026/rails/game/specific/_1835 Modified Files: GameManager_1835.java Log Message: Fixed 1835 bug at buying the first 5-train. Fixed Hamburg tile orientation: can no longer rotate. Index: GameManager_1835.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/GameManager_1835.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GameManager_1835.java 15 Apr 2010 19:49:50 -0000 1.8 --- GameManager_1835.java 15 May 2010 19:05:39 -0000 1.9 *************** *** 37,46 **** } else { PhaseI phase = getCurrentPhase(); ! if (phase.getName().equals("4") || phase.getName().equals("4+4") ! || phase.getName().equals("5")) { ! if (!PrussianFormationRound.prussianIsComplete(this)) { ! previousRound = round; ! startPrussianFormationRound (null); ! } } else { super.nextRound(round); --- 37,45 ---- } else { PhaseI phase = getCurrentPhase(); ! if ((phase.getName().equals("4") || phase.getName().equals("4+4") ! || phase.getName().equals("5")) ! && !PrussianFormationRound.prussianIsComplete(this)) { ! previousRound = round; ! startPrussianFormationRound (null); } else { super.nextRound(round); |
From: Erik V. <ev...@us...> - 2010-05-15 16:36:20
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5643/rails/ui/swing Modified Files: ORUIManager.java ORPanel.java Log Message: Rewritten code to assign next operating company to avoid the OperatingCompanyIndex state object. This was continually causing problems. Also partial implementation of 18EU bankruptcy; game currently hangs if this occurs. Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -d -r1.73 -r1.74 *** ORUIManager.java 14 May 2010 15:19:57 -0000 1.73 --- ORUIManager.java 15 May 2010 16:36:09 -0000 1.74 *************** *** 112,116 **** public void initOR(OperatingRound or) { oRound = or; ! companies = (oRound).getOperatingCompanies(); map.updateOffBoardToolTips(); orWindow.activate(oRound); --- 112,116 ---- public void initOR(OperatingRound or) { oRound = or; ! companies = (oRound).getOperatingCompanies().toArray(new PublicCompanyI[0]); map.updateOffBoardToolTips(); orWindow.activate(oRound); *************** *** 1103,1109 **** JOptionPane.QUESTION_MESSAGE, null, options, options[0]); ! int index = oldTrainOptions.indexOf(exchangedTrainName); ! if (index >= 0) { ! exchangedTrain = oldTrains.get(index); } } --- 1103,1115 ---- JOptionPane.QUESTION_MESSAGE, null, options, options[0]); ! if (exchangedTrainName != null) { ! int index = oldTrainOptions.indexOf(exchangedTrainName); ! if (index >= 0) { ! exchangedTrain = oldTrains.get(index); ! } ! } ! if (exchangedTrain == null) { ! // No valid train selected - cancel the buy action ! train = null; } } Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** ORPanel.java 14 May 2010 15:19:58 -0000 1.63 --- ORPanel.java 15 May 2010 16:36:09 -0000 1.64 *************** *** 145,149 **** if (round instanceof OperatingRound) { ! companies = ((OperatingRound) round).getOperatingCompanies(); nc = companies.length; } --- 145,149 ---- if (round instanceof OperatingRound) { ! companies = ((OperatingRound) round).getOperatingCompanies().toArray(new PublicCompanyI[0]); nc = companies.length; } *************** *** 218,222 **** log.debug("ORPanel.recreate() called"); ! companies = or.getOperatingCompanies(); nc = companies.length; --- 218,222 ---- log.debug("ORPanel.recreate() called"); ! companies = or.getOperatingCompanies().toArray(new PublicCompanyI[0]); nc = companies.length; *************** *** 603,607 **** RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company, gm.getCurrentPhase()); ra.populateFromRails(); ! boolean anotherTrain = true; while (anotherTrain) { --- 603,607 ---- RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company, gm.getCurrentPhase()); ra.populateFromRails(); ! boolean anotherTrain = true; while (anotherTrain) { |
From: Erik V. <ev...@us...> - 2010-05-15 16:36:17
|
Update of /cvsroot/rails/18xx/data/18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5643/data/18EU Modified Files: Game.xml Log Message: Rewritten code to assign next operating company to avoid the OperatingCompanyIndex state object. This was continually causing problems. Also partial implementation of 18EU bankruptcy; game currently hangs if this occurs. Index: Game.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/18EU/Game.xml,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Game.xml 27 Apr 2010 23:25:41 -0000 1.20 --- Game.xml 15 May 2010 16:36:09 -0000 1.21 *************** *** 25,29 **** </GuiClasses> <EndOfGame> - <Bankruptcy/> <BankBreaks limit="0" finish="setOfORs"/> <!-- "Runs out"; when "broken", -1 is the limit --> --- 25,28 ---- |
From: Erik V. <ev...@us...> - 2010-05-15 16:36:17
|
Update of /cvsroot/rails/18xx/rails/game/specific/_18EU In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5643/rails/game/specific/_18EU Modified Files: StockRound_18EU.java OperatingRound_18EU.java Log Message: Rewritten code to assign next operating company to avoid the OperatingCompanyIndex state object. This was continually causing problems. Also partial implementation of 18EU bankruptcy; game currently hangs if this occurs. Index: StockRound_18EU.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/StockRound_18EU.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** StockRound_18EU.java 9 May 2010 22:00:26 -0000 1.38 --- StockRound_18EU.java 15 May 2010 16:36:09 -0000 1.39 *************** *** 692,700 **** discardingTrains.set(true); ! // Make up a list of train discarding companies in sequence of the ! // last OR ! // TODO: this disregards any changes in the operating sequence ! // during the last OR. This is probably wrong. ! PublicCompanyI[] operatingCompanies = getOperatingCompanies(); discardingCompanies = new PublicCompanyI[compWithExcessTrains.size()]; --- 692,697 ---- discardingTrains.set(true); ! // Make up a list of train discarding companies in operating sequence. ! PublicCompanyI[] operatingCompanies = setOperatingCompanies().toArray(new PublicCompanyI[0]); discardingCompanies = new PublicCompanyI[compWithExcessTrains.size()]; Index: OperatingRound_18EU.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_18EU/OperatingRound_18EU.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** OperatingRound_18EU.java 26 Jan 2010 19:50:45 -0000 1.14 --- OperatingRound_18EU.java 15 May 2010 16:36:09 -0000 1.15 *************** *** 114,118 **** /* Other company trains, sorted by president (current player first) */ if (getCurrentPhase().isTrainTradingAllowed()) { - PublicCompanyI c; Player p; Portfolio pf; --- 114,117 ---- *************** *** 127,132 **** List<PublicCompanyI> companies; // Sort out which players preside over wich companies. ! for (int j = 0; j < operatingCompanyArray.length; j++) { ! c = operatingCompanyArray[j]; if (c == operatingCompany) continue; p = c.getPresident(); --- 126,130 ---- List<PublicCompanyI> companies; // Sort out which players preside over wich companies. ! for (PublicCompanyI c : operatingCompanies) { if (c == operatingCompany) continue; p = c.getPresident(); *************** *** 187,191 **** // one to act in the Final Minor Exchange Round. if (result && gameManager.getPhaseManager().hasReachedPhase("5") ! && operatingCompanyArray[0].getTypeName().equals("Minor") && ((GameManager_18EU)gameManager).getPlayerToStartFMERound() == null) { ((GameManager_18EU)gameManager).setPlayerToStartFMERound(operatingCompany.getPresident()); --- 185,189 ---- // one to act in the Final Minor Exchange Round. if (result && gameManager.getPhaseManager().hasReachedPhase("5") ! && operatingCompanies.get(0).getTypeName().equalsIgnoreCase("Minor") && ((GameManager_18EU)gameManager).getPlayerToStartFMERound() == null) { ((GameManager_18EU)gameManager).setPlayerToStartFMERound(operatingCompany.getPresident()); *************** *** 206,210 **** int numberOfTrains; ! for (PublicCompanyI comp : operatingCompanyArray) { portfolio = comp.getPortfolio(); numberOfTrains = portfolio.getNumberOfTrains(); --- 204,208 ---- int numberOfTrains; ! for (PublicCompanyI comp : operatingCompanies) { portfolio = comp.getPortfolio(); numberOfTrains = portfolio.getNumberOfTrains(); |
From: Erik V. <ev...@us...> - 2010-05-15 16:36:17
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1835 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5643/rails/game/specific/_1835 Modified Files: FoldIntoPrussian.java OperatingRound_1835.java Log Message: Rewritten code to assign next operating company to avoid the OperatingCompanyIndex state object. This was continually causing problems. Also partial implementation of 18EU bankruptcy; game currently hangs if this occurs. Index: OperatingRound_1835.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/OperatingRound_1835.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** OperatingRound_1835.java 8 May 2010 14:33:32 -0000 1.8 --- OperatingRound_1835.java 15 May 2010 16:36:09 -0000 1.9 *************** *** 170,175 **** int index = 0; ! int operatingCompanyIndex = operatingCompanyIndexObject.intValue(); ! for (PublicCompanyI company : getOperatingCompanies()) { if (index > operatingCompanyIndex && company.hasStockPrice() --- 170,175 ---- int index = 0; ! int operatingCompanyIndex = getOperatingCompanyIndex(); ! for (PublicCompanyI company : setOperatingCompanies()) { if (index > operatingCompanyIndex && company.hasStockPrice() *************** *** 185,192 **** } // Insert PR at the found index (possibly at the end) ! List<PublicCompanyI> companies ! = new ArrayList<PublicCompanyI>(Arrays.asList(operatingCompanyArray)); ! companies.add(index, prussian); ! operatingCompanyArray = companies.toArray(new PublicCompanyI[0]); log.debug("PR will operate at order position "+index); --- 185,189 ---- } // Insert PR at the found index (possibly at the end) ! operatingCompanies.add(index, prussian); log.debug("PR will operate at order position "+index); Index: FoldIntoPrussian.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1835/FoldIntoPrussian.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** FoldIntoPrussian.java 7 May 2010 20:03:48 -0000 1.2 --- FoldIntoPrussian.java 15 May 2010 16:36:09 -0000 1.3 *************** *** 81,84 **** --- 81,86 ---- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { + + CompanyI company; in.defaultReadObject(); *************** *** 94,98 **** foldedCompanies = new ArrayList<CompanyI>(); for (String name : foldedCompanyNames.split(",")) { ! foldedCompanies.add(cmgr.getPublicCompany(name)); } } --- 96,102 ---- foldedCompanies = new ArrayList<CompanyI>(); for (String name : foldedCompanyNames.split(",")) { ! company = cmgr.getPublicCompany(name); ! if (company == null) company = cmgr.getPrivateCompany(name); ! if (company != null) foldedCompanies.add(company); } } |
From: Erik V. <ev...@us...> - 2010-05-15 16:36:17
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5643/rails/game/specific/_1856 Modified Files: OperatingRound_1856.java CGRFormationRound.java Log Message: Rewritten code to assign next operating company to avoid the OperatingCompanyIndex state object. This was continually causing problems. Also partial implementation of 18EU bankruptcy; game currently hangs if this occurs. Index: CGRFormationRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/CGRFormationRound.java,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** CGRFormationRound.java 15 Apr 2010 19:49:50 -0000 1.34 --- CGRFormationRound.java 15 May 2010 16:36:09 -0000 1.35 *************** *** 72,76 **** // Collect companies having loans ! for (PublicCompanyI company : getOperatingCompanies()) { if (company.getCurrentNumberOfLoans() > 0) { if (companiesToRepayLoans == null) { --- 72,76 ---- // Collect companies having loans ! for (PublicCompanyI company : setOperatingCompanies()) { if (company.getCurrentNumberOfLoans() > 0) { if (companiesToRepayLoans == null) { Index: OperatingRound_1856.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/OperatingRound_1856.java,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** OperatingRound_1856.java 22 Apr 2010 19:09:58 -0000 1.35 --- OperatingRound_1856.java 15 May 2010 16:36:09 -0000 1.36 *************** *** 47,105 **** protected boolean setNextOperatingCompany(boolean initial) { ! ! if (operatingCompanyIndexObject == null) { ! operatingCompanyIndexObject = ! new IntegerState("OperatingCompanyIndex"); ! } ! while (true) { ! if (initial) { ! operatingCompanyIndexObject.set(0); initial = false; } else { ! operatingCompanyIndexObject.add(1); } ! int operatingCompanyIndex = operatingCompanyIndexObject.intValue(); ! ! if (operatingCompanyIndex >= operatingCompanyArray.length) { ! return false; ! } else { ! operatingCompany = operatingCompanyArray[operatingCompanyIndex]; ! // 1856 special: check if the company has sold enough shares to operate ! // This check does not apply to the CGR ! if (operatingCompany instanceof PublicCompany_CGR) return true; ! ! if (operatingCompany.isClosed()) continue; ! if (!operatingCompany.hasOperated()) { ! int soldPercentage = getSoldPercentage (operatingCompany); ! TrainI nextAvailableTrain = gameManager.getTrainManager().getAvailableNewTrains().get(0); ! int trainNumber; ! try { ! trainNumber = Integer.parseInt(nextAvailableTrain.getName()); ! } catch (NumberFormatException e) { ! trainNumber = 6; // Diesel! ! } ! int floatPercentage = 10 * trainNumber; ! log.debug ("Float percentage is "+floatPercentage ! +" sold percentage is "+soldPercentage); - if (soldPercentage < floatPercentage) { - DisplayBuffer.add(LocalText.getText("MayNotYetOperate", - operatingCompany.getName(), - String.valueOf(soldPercentage), - String.valueOf(floatPercentage) - )); - // Company may not yet operate - continue; - } } - return true; } } } --- 47,97 ---- protected boolean setNextOperatingCompany(boolean initial) { ! //log.debug("+++ old OC is "+(operatingCompany!=null?operatingCompany.getName():"null")); while (true) { ! if (initial || operatingCompany == null || operatingCompanyObject == null) { ! setOperatingCompany(operatingCompanies.get(0)); initial = false; } else { ! int index = operatingCompanies.indexOf(operatingCompany); ! if (++index >= operatingCompanies.size()) { ! return false; ! } ! setOperatingCompany(operatingCompanies.get(index)); } ! // 1856 special: check if the company has sold enough shares to operate ! // This check does not apply to the CGR ! if (operatingCompany instanceof PublicCompany_CGR) return true; ! if (operatingCompany.isClosed()) continue; ! if (!operatingCompany.hasOperated()) { ! int soldPercentage = getSoldPercentage (operatingCompany); ! TrainI nextAvailableTrain = gameManager.getTrainManager().getAvailableNewTrains().get(0); ! int trainNumber; ! try { ! trainNumber = Integer.parseInt(nextAvailableTrain.getName()); ! } catch (NumberFormatException e) { ! trainNumber = 6; // Diesel! ! } ! int floatPercentage = 10 * trainNumber; + log.debug ("Float percentage is "+floatPercentage + +" sold percentage is "+soldPercentage); + if (soldPercentage < floatPercentage) { + DisplayBuffer.add(LocalText.getText("MayNotYetOperate", + operatingCompany.getName(), + String.valueOf(soldPercentage), + String.valueOf(floatPercentage) + )); + // Company may not yet operate + continue; } } + //log.debug("+++ new OC is "+(operatingCompany!=null?operatingCompany.getName():"null")); + return true; } } *************** *** 278,282 **** List<PublicCompanyI> possibleDestinations = new ArrayList<PublicCompanyI>(); ! for (PublicCompanyI comp : operatingCompanyArray) { if (comp.hasDestination() && ((PublicCompany_1856)comp).getTrainNumberAvailableAtStart() < 5 --- 270,274 ---- List<PublicCompanyI> possibleDestinations = new ArrayList<PublicCompanyI>(); ! for (PublicCompanyI comp : operatingCompanies) { if (comp.hasDestination() && ((PublicCompany_1856)comp).getTrainNumberAvailableAtStart() < 5 *************** *** 473,477 **** if (!resetOperatingCompanies(mergingCompanies)) return; ! if (operatingCompany != null) { setStep(GameDef.OrStep.INITIAL); } else { --- 465,469 ---- if (!resetOperatingCompanies(mergingCompanies)) return; ! if (getOperatingCompany() != null) { setStep(GameDef.OrStep.INITIAL); } else { *************** *** 483,490 **** private boolean resetOperatingCompanies(List<PublicCompanyI> mergingCompanies) { - List<PublicCompanyI> companies - = new ArrayList<PublicCompanyI>(Arrays.asList(operatingCompanyArray)); PublicCompanyI cgr = companyManager.getPublicCompany(PublicCompany_CGR.NAME); boolean cgrCanOperate = cgr.hasStarted(); for (PublicCompanyI company : mergingCompanies) { --- 475,481 ---- private boolean resetOperatingCompanies(List<PublicCompanyI> mergingCompanies) { PublicCompanyI cgr = companyManager.getPublicCompany(PublicCompany_CGR.NAME); boolean cgrCanOperate = cgr.hasStarted(); + boolean roundFinished = false; for (PublicCompanyI company : mergingCompanies) { *************** *** 494,499 **** // Find the first company that has not yet operated // and is not closed. ! while (setNextOperatingCompany(false) ! && operatingCompany.isClosed()); // Remove closed companies from the operating company list --- 485,490 ---- // Find the first company that has not yet operated // and is not closed. ! //while (setNextOperatingCompany(false) ! // && operatingCompany.isClosed()); // Remove closed companies from the operating company list *************** *** 510,514 **** //} ! for (PublicCompanyI c : companies) { if (c.isClosed()) { log.info(c.getName()+" is closed"); --- 501,505 ---- //} ! for (PublicCompanyI c : operatingCompanies) { if (c.isClosed()) { log.info(c.getName()+" is closed"); *************** *** 519,536 **** String message; ! int operatingCompanyIndex = operatingCompanyIndexObject.intValue(); if (cgr.hasStarted()) { if (cgrCanOperate) { operatingCompanyIndex = Math.max (0, operatingCompanyIndex); ! companies.add(operatingCompanyIndex, cgr); ! operatingCompany = cgr; ! operatingCompanyIndex = companies.indexOf(operatingCompany); message = LocalText.getText("CanOperate", cgr.getName()); } else { message = LocalText.getText("CannotOperate", cgr.getName()); ! // Find the first company that has not yet operated ! // and is not closed. ! while (setNextOperatingCompany(false) ! && operatingCompany.isClosed()); } } else { --- 510,523 ---- String message; ! int operatingCompanyIndex = getOperatingCompanyIndex(); if (cgr.hasStarted()) { if (cgrCanOperate) { operatingCompanyIndex = Math.max (0, operatingCompanyIndex); ! operatingCompanies.add(operatingCompanyIndex, cgr); ! setOperatingCompany(cgr); message = LocalText.getText("CanOperate", cgr.getName()); } else { message = LocalText.getText("CannotOperate", cgr.getName()); ! roundFinished = !setNextOperatingCompany(false); } } else { *************** *** 543,550 **** DisplayBuffer.add(message); ! operatingCompanyArray = companies.toArray(new PublicCompanyI[0]); ! ! if (operatingCompanyIndex < operatingCompanyArray.length) { ! operatingCompanyIndexObject.set(operatingCompanyIndex); log.debug ("Next operating company: "+operatingCompany.getName()); } else { --- 530,536 ---- DisplayBuffer.add(message); ! // Find the first company that has not yet operated ! // and is not closed. ! if (!roundFinished) { log.debug ("Next operating company: "+operatingCompany.getName()); } else { |
From: Erik V. <ev...@us...> - 2010-05-15 16:36:17
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv5643/rails/game Modified Files: Round.java OperatingRound.java GameManager.java Log Message: Rewritten code to assign next operating company to avoid the OperatingCompanyIndex state object. This was continually causing problems. Also partial implementation of 18EU bankruptcy; game currently hangs if this occurs. Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.129 retrieving revision 1.130 diff -C2 -d -r1.129 -r1.130 *** OperatingRound.java 13 May 2010 09:51:32 -0000 1.129 --- OperatingRound.java 15 May 2010 16:36:09 -0000 1.130 *************** *** 11,14 **** --- 11,15 ---- import rails.game.special.*; import rails.game.state.EnumState; + import rails.game.state.GenericState; import rails.game.state.IntegerState; import rails.util.LocalText; *************** *** 33,41 **** = new ArrayList<PublicCompanyI> (); ! protected PublicCompanyI[] operatingCompanyArray; ! protected IntegerState operatingCompanyIndexObject; ! protected PublicCompanyI operatingCompany; // Non-persistent lists (are recreated after each user action) --- 34,43 ---- = new ArrayList<PublicCompanyI> (); ! protected List<PublicCompanyI> operatingCompanies; ! //protected IntegerState operatingCompanyIndexObject; ! protected GenericState<PublicCompanyI> operatingCompanyObject; ! protected PublicCompanyI operatingCompany = null; // Non-persistent lists (are recreated after each user action) *************** *** 94,98 **** super (gameManager); ! operatingCompanyArray = super.getOperatingCompanies(); // sfy NoMapMode --- 96,100 ---- super (gameManager); ! operatingCompanies = setOperatingCompanies(); // sfy NoMapMode *************** *** 112,119 **** privatesPayOut(); ! if (operatingCompanyArray.length > 0) { StringBuilder msg = new StringBuilder(); ! for (PublicCompanyI company : operatingCompanyArray) { msg.append(",").append(company.getName()); } --- 114,121 ---- privatesPayOut(); ! if (operatingCompanies.size() > 0) { StringBuilder msg = new StringBuilder(); ! for (PublicCompanyI company : operatingCompanies) { msg.append(",").append(company.getName()); } *************** *** 1491,1540 **** protected boolean setNextOperatingCompany(boolean initial) { - - if (operatingCompanyIndexObject == null) { - operatingCompanyIndexObject = - new IntegerState("OperatingCompanyIndex"); - } - /* - if (initial) { - operatingCompanyIndexObject.set(0); - } else { - operatingCompanyIndexObject.add(1); - } - - int operatingCompanyIndex = operatingCompanyIndexObject.intValue(); - - if (operatingCompanyIndex >= operatingCompanyArray.length) { - operatingCompany = null; - return false; - } else { - operatingCompany = operatingCompanyArray[operatingCompanyIndex]; - log.debug("Operating company is "+operatingCompany.getName()+" in "+getRoundName()); - return true; - } - */ - // The above logic doesn't work if companies have closed in the meantime. - // The new logic below originates from OperatingRound_1856 while (true) { ! if (initial) { ! operatingCompanyIndexObject.set(0); initial = false; } else { ! operatingCompanyIndexObject.add(1); } ! int operatingCompanyIndex = operatingCompanyIndexObject.intValue(); ! ! if (operatingCompanyIndex >= operatingCompanyArray.length) { ! return false; ! } else { ! operatingCompany = operatingCompanyArray[operatingCompanyIndex]; ! ! if (operatingCompany.isClosed()) continue; ! return true; ! } } ! } --- 1493,1522 ---- protected boolean setNextOperatingCompany(boolean initial) { while (true) { ! if (initial || operatingCompany == null || operatingCompanyObject == null) { ! setOperatingCompany(operatingCompanies.get(0)); initial = false; } else { ! int index = operatingCompanies.indexOf(operatingCompany); ! if (++index >= operatingCompanies.size()) { ! return false; ! } ! setOperatingCompany(operatingCompanies.get(index)); } ! if (operatingCompany.isClosed()) continue; ! return true; } ! } ! ! protected void setOperatingCompany (PublicCompanyI company) { ! if (operatingCompanyObject == null) { ! operatingCompanyObject = ! new GenericState<PublicCompanyI>("OperatingCompanyIndex", company); ! } else { ! operatingCompanyObject.set(company); ! } ! operatingCompany = company; } *************** *** 1754,1758 **** excessTrainCompanies = new HashMap<Player, List<PublicCompanyI>>(); Player player; ! for (PublicCompanyI comp : operatingCompanyArray) { if (comp.getPortfolio().getNumberOfTrains() > comp.getTrainLimit(getCurrentPhase().getIndex())) { player = comp.getPresident(); --- 1736,1740 ---- excessTrainCompanies = new HashMap<Player, List<PublicCompanyI>>(); Player player; ! for (PublicCompanyI comp : operatingCompanies) { if (comp.getPortfolio().getNumberOfTrains() > comp.getTrainLimit(getCurrentPhase().getIndex())) { player = comp.getPresident(); *************** *** 2186,2195 **** */ public PublicCompanyI getOperatingCompany() { ! return operatingCompany; } ! ! @Override ! public PublicCompanyI[] getOperatingCompanies() { ! return operatingCompanyArray; } --- 2168,2176 ---- */ public PublicCompanyI getOperatingCompany() { ! return operatingCompanyObject.getObject(); } ! ! public List<PublicCompanyI> getOperatingCompanies() { ! return operatingCompanies; } *************** *** 2217,2221 **** public int getOperatingCompanyIndex() { ! return operatingCompanyIndexObject.intValue(); } --- 2198,2202 ---- public int getOperatingCompanyIndex() { ! return operatingCompanies.indexOf(getOperatingCompany()); } *************** *** 2229,2235 **** public boolean setPossibleActions() { ! ! int operatingCompanyIndex = operatingCompanyIndexObject.intValue(); ! operatingCompany = operatingCompanyArray[operatingCompanyIndex]; /* Create a new list of possible actions for the UI */ --- 2210,2214 ---- public boolean setPossibleActions() { ! operatingCompany = getOperatingCompany(); /* Create a new list of possible actions for the UI */ *************** *** 2585,2589 **** /* Other company trains, sorted by president (current player first) */ if (getCurrentPhase().isTrainTradingAllowed()) { - PublicCompanyI c; BuyTrain bt; Player p; --- 2564,2567 ---- *************** *** 2599,2604 **** List<PublicCompanyI> companies; // Sort out which players preside over which companies. ! for (int j = 0; j < operatingCompanyArray.length; j++) { ! c = operatingCompanyArray[j]; if (c.isClosed() || c == operatingCompany) continue; p = c.getPresident(); --- 2577,2581 ---- List<PublicCompanyI> companies; // Sort out which players preside over which companies. ! for (PublicCompanyI c : getOperatingCompanies()) { if (c.isClosed() || c == operatingCompany) continue; p = c.getPresident(); Index: Round.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Round.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Round.java 8 May 2010 13:57:31 -0000 1.40 --- Round.java 15 May 2010 16:36:09 -0000 1.41 *************** *** 250,258 **** } ! /** Get the operating companies in their current acting order */ ! public PublicCompanyI[] getOperatingCompanies() { - List<PublicCompanyI> companies = - companyManager.getAllPublicCompanies(); Map<Integer, PublicCompanyI> operatingCompanies = new TreeMap<Integer, PublicCompanyI>(); --- 250,256 ---- } ! /** Set the operating companies in their current acting order */ ! public List<PublicCompanyI> setOperatingCompanies() { Map<Integer, PublicCompanyI> operatingCompanies = new TreeMap<Integer, PublicCompanyI>(); *************** *** 260,264 **** int key; int minorNo = 0; ! for (PublicCompanyI company : companies) { if (!canCompanyOperateThisRound(company)) continue; --- 258,262 ---- int key; int minorNo = 0; ! for (PublicCompanyI company : companyManager.getAllPublicCompanies()) { if (!canCompanyOperateThisRound(company)) continue; *************** *** 278,282 **** } ! return operatingCompanies.values().toArray(new PublicCompanyI[0]); } --- 276,280 ---- } ! return new ArrayList<PublicCompanyI>(operatingCompanies.values()); } Index: GameManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/GameManager.java,v retrieving revision 1.100 retrieving revision 1.101 diff -C2 -d -r1.100 -r1.101 *** GameManager.java 8 May 2010 13:56:30 -0000 1.100 --- GameManager.java 15 May 2010 16:36:09 -0000 1.101 *************** *** 1006,1009 **** --- 1006,1047 ---- if (gameEndsWithBankruptcy) { finishGame(); + } else { + Player player, newPresident; + int numberOfPlayers = getNumberOfPlayers(); + int maxShare; + int share; + + // Assume default case as in 18EU: all assets to Bank/Pool + Player bankrupter = getCurrentPlayer(); + new CashMove (bankrupter, bank, bankrupter.getCash()); + Portfolio bpf = bankrupter.getPortfolio(); + List<PublicCompanyI> presidencies = new ArrayList<PublicCompanyI>(); + for (PublicCertificateI cert : bpf.getCertificates()) { + if (cert.isPresidentShare()) presidencies.add(cert.getCompany()); + } + for (PublicCompanyI company : presidencies) { + // Check if the presidency is dumped on someone + newPresident = null; + maxShare = 0; + for (int index=getCurrentPlayerIndex()+1; + index<getCurrentPlayerIndex()+numberOfPlayers; index++) { + player = getPlayerByIndex(index%numberOfPlayers); + share = player.getPortfolio().getShare(company); + if (share >= company.getPresidentsShare().getShare() + && (share > maxShare)) { + maxShare = share; + newPresident = player; + } + } + if (newPresident != null) { + bankrupter.getPortfolio().swapPresidentCertificate(company, + newPresident.getPortfolio()); + } else { + company.setClosed(); + // TODO: can be restarted (in 18EU) + } + } + // Dump all shares + Util.moveObjects(bankrupter.getPortfolio().getCertificates(), bank.getPool()); } } |
From: Stefan F. <ste...@us...> - 2010-05-14 15:20:06
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv8794/rails/ui/swing Modified Files: ORUIManager.java ORPanel.java Log Message: Updated and refactored revenue calculation, added support for 1835 Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** ORUIManager.java 13 May 2010 09:51:32 -0000 1.72 --- ORUIManager.java 14 May 2010 15:19:57 -0000 1.73 *************** *** 129,133 **** nwGraph.generateGraph(mapManager.getHexesAsList()); SimpleGraph<NetworkVertex, NetworkEdge> graph = ! nwGraph.getRailRoadGraph(orComp); return graph; } --- 129,133 ---- nwGraph.generateGraph(mapManager.getHexesAsList()); SimpleGraph<NetworkVertex, NetworkEdge> graph = ! nwGraph.getRailRoadGraph(orComp, true); return graph; } *************** *** 1103,1115 **** JOptionPane.QUESTION_MESSAGE, null, options, options[0]); ! if (exchangedTrainName != null) { ! int index = oldTrainOptions.indexOf(exchangedTrainName); ! if (index >= 0) { ! exchangedTrain = oldTrains.get(index); ! } ! } ! if (exchangedTrain == null) { ! // No valid train selected - cancel the buy action ! train = null; } } --- 1103,1109 ---- JOptionPane.QUESTION_MESSAGE, null, options, options[0]); ! int index = oldTrainOptions.indexOf(exchangedTrainName); ! if (index >= 0) { ! exchangedTrain = oldTrains.get(index); } } Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** ORPanel.java 11 May 2010 21:47:21 -0000 1.62 --- ORPanel.java 14 May 2010 15:19:58 -0000 1.63 *************** *** 601,628 **** CompanyManagerI cm = gm.getCompanyManager(); PublicCompanyI company = cm.getPublicCompany(companyName); ! RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company); ! ! // get trains ! company.getPortfolio().getTrainList(); ! for (TrainI train:company.getPortfolio().getTrainList()) ! ra.addTrain(train); boolean anotherTrain = true; while (anotherTrain) { int revenueValue; ! // create results ! // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), false); ! // ra.populateRevenueCalculator(company, gm.getCurrentPhase(), false); ! // log.info("Revenue Adapter:" + ra); ! // revenueValue = ra.calculateRevenue(); ! // log.info("Revenue Value:" + revenueValue); ! // log.info("Revenue run:" + ra.getOptimalRunPrettyPrint()); ! // JOptionPane.showMessageDialog(orWindow, "Without Prediction: RevenueValue = " + revenueValue + ! // "\n RevenueRun = " + ra.getOptimalRunPrettyPrint()); ! // ! // ra.refreshRevenueCalculator(); ! ! // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), true); ! ra.populateRevenueCalculator(gm.getCurrentPhase(), true); log.info("Revenue Adapter:" + ra); revenueValue = ra.calculateRevenue(); --- 601,611 ---- CompanyManagerI cm = gm.getCompanyManager(); PublicCompanyI company = cm.getPublicCompany(companyName); ! RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company, gm.getCurrentPhase()); ! ra.populateFromRails(); boolean anotherTrain = true; while (anotherTrain) { int revenueValue; ! ra.initRevenueCalculator(); log.info("Revenue Adapter:" + ra); revenueValue = ra.calculateRevenue(); *************** *** 642,646 **** } else { ra.addTrainByString(trainsToAdd); - ra.refreshRevenueCalculator(); } } --- 625,628 ---- *************** *** 804,833 **** NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); nwGraph.generateGraph(mapManager.getHexesAsList()); ! // run on mapgraph ! // SimpleGraph<NetworkVertex, NetworkEdge> mapGraph = nwGraph.getMapGraph(); ! // ! // mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); ! // ! // // revenue calculation example ! // mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); ! // RevenueAdapter ra = new RevenueAdapter(mapGraph); ! // ! // // set tokens ! // List<TokenI> tokens = company.getTokens(); ! // for (TokenI token:tokens){ ! // NetworkVertex vertex = nwGraph.getVertex(token); ! // if (vertex != null) ra.addStartVertex(vertex); ! // } ! ! // run on railroad graph, does not work so far, thus use map graph ! RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company); ! ! // get trains ! company.getPortfolio().getTrainList(); ! for (TrainI train:company.getPortfolio().getTrainList()) { ! ra.addTrain(train); ! } ! ! ra.populateRevenueCalculator(gm.getCurrentPhase(), true); ra.addRevenueListener(this); --- 786,792 ---- NetworkGraphBuilder nwGraph = new NetworkGraphBuilder(); nwGraph.generateGraph(mapManager.getHexesAsList()); ! RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company, gm.getCurrentPhase()); ! ra.populateFromRails(); ! ra.initRevenueCalculator(); ra.addRevenueListener(this); |
From: Stefan F. <ste...@us...> - 2010-05-14 15:20:06
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv8794/rails/algorithms Modified Files: NetworkTrain.java RevenueAdapter.java RevenueBonus.java RevenueBonusTemplate.java NetworkGraphBuilder.java RevenueCalculator.java Added Files: RevenueTrainRun.java Log Message: Updated and refactored revenue calculation, added support for 1835 Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RevenueCalculator.java 12 May 2010 18:50:26 -0000 1.12 --- RevenueCalculator.java 14 May 2010 15:19:57 -0000 1.13 *************** *** 10,13 **** --- 10,14 ---- private final int nbTrains; private final int nbEdges; + private final int nbBonuses; // static vertex data *************** *** 17,24 **** private final int[] vertexNbNeighbors; private final int[] vertexNbVisitSets; private final int[][] vertexNeighbors; private final int[][] vertexEdges; ! private final int[][] vertexVisitSets; // start vertexes --- 18,27 ---- private final int[] vertexNbNeighbors; private final int[] vertexNbVisitSets; + private final int[] vertexNbBonusSets; private final int[][] vertexNeighbors; private final int[][] vertexEdges; ! private final int[][] vertexVisitSets; // vertex belongs to a visit set, dimension: nbVertex x maxBlocks ! private final int[][] vertexBonusSets; // vertex belongs to a bonus set, dimension: nbVertex x nbBonuses // start vertexes *************** *** 48,52 **** --- 51,65 ---- private final int [] trainStartEdge; + // static bonus data + private final int [] bonusValue; + private final boolean [][] bonusActiveForTrain; // dimensions: bonus x train + private final int [] bonusRequiresVertices; + + // dynamic bonus data + private final int [][] bonusTrainVertices; + // run settings + private int startTrainSet; + private int finalTrainSet; private int startTrain; private int finalTrain; *************** *** 85,99 **** ! public RevenueCalculator (RevenueAdapter revenueAdapter, int nbVertexes, int nbEdges, int maxNeighbors, int maxBlocks, int nbTrains) { log.info("RC defined: nbVertexes = " + nbVertexes + ", nbEdges = " + nbEdges + ", maxNeighbors = " + maxNeighbors + ! ", maxBlocks = " + maxBlocks + ", nbTrains = " + nbTrains); this.revenueAdapter = revenueAdapter; this.nbVertexes = nbVertexes; this.nbEdges = nbEdges; - this.nbTrains = nbTrains; ! // initialize all required variables --- 98,112 ---- ! public RevenueCalculator (RevenueAdapter revenueAdapter, int nbVertexes, int nbEdges, ! int maxNeighbors, int maxVertexSets, int nbTrains, int nbBonuses) { log.info("RC defined: nbVertexes = " + nbVertexes + ", nbEdges = " + nbEdges + ", maxNeighbors = " + maxNeighbors + ! ", maxVertexSets = " + maxVertexSets + ", nbTrains = " + nbTrains + ", nbBonuses = " + nbBonuses ); this.revenueAdapter = revenueAdapter; this.nbVertexes = nbVertexes; this.nbEdges = nbEdges; this.nbTrains = nbTrains; ! this.nbBonuses = nbBonuses; // initialize all required variables *************** *** 103,109 **** vertexNbNeighbors = new int[nbVertexes]; vertexNbVisitSets = new int[nbVertexes]; vertexNeighbors = new int[nbVertexes][maxNeighbors]; vertexEdges = new int[nbVertexes][maxNeighbors]; ! vertexVisitSets = new int[nbVertexes][maxBlocks]; edgeGreedy = new boolean[nbEdges]; --- 116,124 ---- vertexNbNeighbors = new int[nbVertexes]; vertexNbVisitSets = new int[nbVertexes]; + vertexNbBonusSets = new int[nbVertexes]; vertexNeighbors = new int[nbVertexes][maxNeighbors]; vertexEdges = new int[nbVertexes][maxNeighbors]; ! vertexVisitSets = new int[nbVertexes][maxVertexSets]; ! vertexBonusSets = new int[nbVertexes][nbBonuses]; edgeGreedy = new boolean[nbEdges]; *************** *** 119,129 **** trainMinors = new int[nbTrains]; trainVisited = new boolean[nbTrains][nbVertexes]; ! trainVertexStack = new int[nbTrains][nbVertexes]; ! trainEdgeStack = new int[nbTrains][nbVertexes]; trainStackPos = new int[nbTrains]; trainBottomPos = new int[nbTrains]; trainStartEdge = new int[nbTrains]; ! currentBestRun = new int[nbTrains][nbVertexes]; useRevenuePrediction = false; --- 134,150 ---- 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]; trainStartEdge = new int[nbTrains]; ! bonusValue = new int[nbBonuses]; ! bonusRequiresVertices = new int[nbBonuses]; ! bonusActiveForTrain = new boolean[nbBonuses][nbTrains]; ! bonusTrainVertices = new int[nbBonuses][nbTrains]; ! ! currentBestRun = new int[nbTrains][nbVertexes + 1]; useRevenuePrediction = false; *************** *** 133,139 **** vertexMajor[id] = major; vertexMinor[id] = minor; ! // default neighbors && blocks vertexNbNeighbors[id] = 0; vertexNbVisitSets[id] = 0; } --- 154,161 ---- vertexMajor[id] = major; vertexMinor[id] = minor; ! // default neighbors && visit and bonus sets vertexNbNeighbors[id] = 0; vertexNbVisitSets[id] = 0; + vertexNbBonusSets[id] = 0; } *************** *** 151,163 **** } ! ! void setVertexVisitSets(int id, int[] blocks) { ! // copy blocks ! for (int j=0; j < blocks.length; j++) { ! vertexVisitSets[id][j] = blocks[j]; ! } ! vertexNbVisitSets[id] = blocks.length; ! } ! void setStartVertexes(int[] startVertexes) { this.startVertexes = startVertexes; --- 173,177 ---- } ! void setStartVertexes(int[] startVertexes) { this.startVertexes = startVertexes; *************** *** 176,179 **** --- 190,216 ---- } + void setVisitSet(int[] vertices) { + for (int j=0; j < vertices.length; j++) { + int vertexId = vertices[j]; + for (int k=0; k < vertices.length; k++) { + if (k == j) continue; + vertexVisitSets[vertexId][vertexNbVisitSets[vertexId]++] = vertices[k]; + } + } + } + + void setBonus(int id, int value, int[] vertices, boolean[] bonusForTrain) { + log.info("RC: define bonus value = " + value + ", vertices = " + Arrays.toString(vertices) + + ", bonusForTrain = " + Arrays.toString(bonusForTrain)); + + bonusValue[id] = value; + bonusRequiresVertices[id] = vertices.length; + for (int j=0; j < vertices.length; j++) { + int vertexId = vertices[j]; + vertexBonusSets[vertexId][vertexNbBonusSets[vertexId]++] = id; + } + bonusActiveForTrain[id] = bonusForTrain; + } + int[][] getOptimalRun() { log.info("RC: currentBestRun = " + Arrays.deepToString(currentBestRun)); *************** *** 244,250 **** if (startTrain > finalTrain) return; ! useRevenuePrediction = true; this.maxCumulatedTrainRevenues = new int[nbTrains]; initRevenueValues(startTrain, finalTrain); --- 281,293 ---- if (startTrain > finalTrain) return; ! ! this.startTrainSet = startTrain; ! this.finalTrainSet = finalTrain; useRevenuePrediction = true; this.maxCumulatedTrainRevenues = new int[nbTrains]; + for (int i=0; i < nbTrains; i++) { + currentBestRun[i][0] = -1; + } + initRevenueValues(startTrain, finalTrain); *************** *** 255,261 **** log.info("RC: start individual prediction Runs"); - int cumulatedRevenues = 0; int[] maxSingleTrainRevenues = new int[nbTrains]; ! for (int j=finalTrain; j >= startTrain; j--) { this.startTrain = j; this.finalTrain = j; --- 298,303 ---- log.info("RC: start individual prediction Runs"); int[] maxSingleTrainRevenues = new int[nbTrains]; ! for (int j = startTrain; j <= finalTrain; j++) { this.startTrain = j; this.finalTrain = j; *************** *** 265,273 **** " after " + getStatistics()); maxSingleTrainRevenues[j] = currentBestValue; ! cumulatedRevenues += currentBestValue; maxCumulatedTrainRevenues[j] = cumulatedRevenues; } ! if (startTrain == finalTrain-1) return; log.info("RC: start combined prediction runs"); --- 307,318 ---- " after " + getStatistics()); maxSingleTrainRevenues[j] = currentBestValue; ! } ! int cumulatedRevenues = 0; ! for (int j = finalTrain; j >= startTrain; j--) { ! cumulatedRevenues += maxSingleTrainRevenues[j]; maxCumulatedTrainRevenues[j] = cumulatedRevenues; } ! if (startTrain == finalTrain - 1) return; log.info("RC: start combined prediction runs"); *************** *** 275,279 **** for (int j=finalTrain - 1; j > startTrain; j--) { this.startTrain = j; ! currentBestValue = 0; runTrain(j); log.info("RC: Best prediction run until train nb. " + j + " value = " + currentBestValue + --- 320,324 ---- for (int j=finalTrain - 1; j > startTrain; j--) { this.startTrain = j; ! // currentBestValue = 0; runTrain(j); log.info("RC: Best prediction run until train nb. " + j + " value = " + currentBestValue + *************** *** 287,293 **** log.info("RC: calculateRevenue trains from " + startTrain + " to " + finalTrain); this.startTrain = startTrain; ! this.finalTrain = finalTrain; ! currentBestValue = 0; runTrain(startTrain); --- 332,346 ---- log.info("RC: calculateRevenue trains from " + startTrain + " to " + finalTrain); + if (!useRevenuePrediction) { + for (int i=0; i < nbTrains; i++) { + currentBestRun[i][0] = -1; + } + } + + this.startTrainSet = startTrain; + this.finalTrainSet = finalTrain; + this.startTrain = startTrain; ! this.finalTrainSet = finalTrain; runTrain(startTrain); *************** *** 302,309 **** log.debug("RC: runTrain " + trainId); ! // intialize value trainCurrentValue[trainId] = 0; ! // initialize lengths trainMajors[trainId] = trainMaxMajors[trainId]; trainMinors[trainId] = trainMaxMinors[trainId]; --- 355,362 ---- log.debug("RC: runTrain " + trainId); ! // initialize value trainCurrentValue[trainId] = 0; ! // initialize train lengths trainMajors[trainId] = trainMaxMajors[trainId]; trainMinors[trainId] = trainMaxMinors[trainId]; *************** *** 313,316 **** --- 366,374 ---- trainBottomPos[trainId] = 0; + // initialize bonuses + for (int b=0; b < nbBonuses; b++) { + bonusTrainVertices[b][trainId] = bonusRequiresVertices[b]; + } + // check if the revenue is enough if (useRevenuePrediction && predictRevenues(trainId)) *************** *** 336,342 **** // then try all edges of it for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { - int neighborId = vertexNeighbors[vertexId][j]; - log.debug("RC: Testing Neighbor Nr. " + j + " of startVertex is " + neighborId); int edgeId = vertexEdges[vertexId][j]; if (travelEdge(trainId, edgeId, true)) { trainStartEdge[trainId] = j; // store start edge --- 394,405 ---- // then try all edges of it for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { int edgeId = vertexEdges[vertexId][j]; + if (edgeUsed[edgeId]) continue; + log.debug("RC: Testing Neighbor Nr. " + j + " of startVertex"); + int neighborId = vertexNeighbors[vertexId][j]; + if (trainVisited[trainId][neighborId]) { + log.debug("RC: Hex already visited"); + continue; + } if (travelEdge(trainId, edgeId, true)) { trainStartEdge[trainId] = j; // store start edge *************** *** 375,378 **** --- 438,443 ---- for (int j = trainStartEdge[trainId] + 1; 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 bottomVertex is " + neighborId); *************** *** 381,385 **** continue; } - int edgeId = vertexEdges[vertexId][j]; if (travelEdge(trainId, edgeId, true)) { nextVertex(trainId, neighborId, edgeGreedy[edgeId]); --- 446,449 ---- *************** *** 415,418 **** --- 479,484 ---- 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); *************** *** 421,425 **** continue; } - int edgeId = vertexEdges[vertexId][j]; if (travelEdge(trainId, edgeId, previousGreedy)) { nextVertex(trainId, neighborId, edgeGreedy[edgeId]); --- 487,490 ---- *************** *** 475,481 **** // check vertex sets for (int j=0; j < vertexNbVisitSets[vertexId]; j++) { ! if (vertexVisitSets[vertexId][j] != -1) { ! trainVisited[trainId][vertexVisitSets[vertexId][j]] = arrive; ! log.debug("RC: visited = " + arrive + " for vertex " + vertexVisitSets[vertexId][j] + " due to block rule"); } } --- 540,565 ---- // check vertex sets for (int j=0; j < vertexNbVisitSets[vertexId]; j++) { ! trainVisited[trainId][vertexVisitSets[vertexId][j]] = arrive; ! log.info("RC: visited = " + arrive + " for vertex " + vertexVisitSets[vertexId][j] + " due to block rule"); ! } ! ! // check bonus sets ! for (int j=0; j < vertexNbBonusSets[vertexId]; j++) { ! int bonusId = vertexBonusSets[vertexId][j]; ! if (!bonusActiveForTrain[bonusId][trainId]) continue; ! if (arrive) { ! bonusTrainVertices[bonusId][trainId]--; ! log.debug("RC: Decreased bonus " + bonusId + " to " + bonusTrainVertices[bonusId][trainId]); ! if (bonusTrainVertices[bonusId][trainId] == 0) { ! trainCurrentValue[trainId] += bonusValue[bonusId]; ! log.debug("RC: Added bonus " + bonusId + " with value " + bonusValue[bonusId]); ! } ! } else { ! if (bonusTrainVertices[bonusId][trainId] == 0) { ! trainCurrentValue[trainId] -= bonusValue[bonusId]; ! log.debug("RC: Removed bonus " + bonusId + " with value " + bonusValue[bonusId]); ! } ! bonusTrainVertices[bonusId][trainId]++; ! log.debug("RC: Increases bonus " + bonusId + " to " + bonusTrainVertices[bonusId][trainId]); } } *************** *** 486,493 **** private boolean travelEdge(int trainId, int edgeId, boolean previousGreedy) { ! if (edgeUsed[edgeId]) { ! log.debug("RC: Edge id " + edgeId + " already used" ); ! return false; ! } else if (previousGreedy || edgeGreedy[edgeId]) { log.debug("RC: Travel edge id " + edgeId); edgeUsed[edgeId] = true; --- 570,574 ---- private boolean travelEdge(int trainId, int edgeId, boolean previousGreedy) { ! if (previousGreedy || edgeGreedy[edgeId]) { log.debug("RC: Travel edge id " + edgeId); edgeUsed[edgeId] = true; *************** *** 561,564 **** --- 642,646 ---- for (int j = startTrain; j <= finalTrain; j++) { totalValue += trainCurrentValue[j]; + // check for two stations requirement not necessary if stationVertex approach works // if (trainIgnoreMinors[j]) { // if (trainMaxMajors[j] - trainMajors[j] >= 2) *************** *** 577,582 **** currentBestValue = totalValue; // exceed thus deep copy of vertex stack ! for (int j = 0; j <= finalTrain; j++) { ! for (int v = 0; v < nbVertexes; v++) { if (v < trainStackPos[j]) { currentBestRun[j][v] = trainVertexStack[j][v]; --- 659,664 ---- currentBestValue = totalValue; // exceed thus deep copy of vertex stack ! for (int j = startTrainSet; j <= finalTrainSet; j++) { ! for (int v = 0; v < nbVertexes + 1; v++) { if (v < trainStackPos[j]) { currentBestRun[j][v] = trainVertexStack[j][v]; *************** *** 622,625 **** --- 704,708 ---- for (int j = startTrain; j < trainId; j++) { totalValue += trainCurrentValue[j]; + // check for two stations requirement not necessary if stationVertex approach works // if (trainIgnoreMinors[j]) { // if (trainMaxMajors[j] - trainMajors[j] >= 2) *************** *** 649,652 **** --- 732,739 ---- buffer.append("vertexNeighbors:" + Arrays.deepToString(vertexNeighbors) + "\n"); buffer.append("vertexEdges:" + Arrays.deepToString(vertexEdges) + "\n"); + buffer.append("vertexVisitSets:" + Arrays.deepToString(vertexVisitSets) + "\n"); + buffer.append("vertexBonusSets:" + Arrays.deepToString(vertexBonusSets) + "\n"); + buffer.append("vertexNbVisitSets:" + Arrays.toString(vertexNbVisitSets) + "\n"); + buffer.append("vertexNbBonusSets:" + Arrays.toString(vertexNbBonusSets) + "\n"); buffer.append("edgeGreedy:" + Arrays.toString(edgeGreedy) + "\n"); buffer.append("edgeDistance:" + Arrays.toString(edgeDistance) + "\n"); Index: RevenueBonusTemplate.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueBonusTemplate.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RevenueBonusTemplate.java 11 May 2010 21:47:21 -0000 1.1 --- RevenueBonusTemplate.java 14 May 2010 15:19:57 -0000 1.2 *************** *** 28,31 **** --- 28,34 ---- private final int value; + // bonus name + private final String name; + // template condition attributes private final List<Integer> identVertices; *************** *** 37,40 **** --- 40,44 ---- value = tag.getAttributeAsInteger("value"); + name = tag.getAttributeAsString("name"); identVertices = new ArrayList<Integer>(); *************** *** 79,83 **** public RevenueBonus toRevenueBonus(MapHex hex, GameManagerI gm, NetworkGraphBuilder ngb) { log.info("Convert " + this); ! RevenueBonus bonus = new RevenueBonus(value); if (!convertVertices(bonus, ngb, hex)) { log.info("Not all vertices found"); --- 83,87 ---- public RevenueBonus toRevenueBonus(MapHex hex, GameManagerI gm, NetworkGraphBuilder ngb) { log.info("Convert " + this); ! RevenueBonus bonus = new RevenueBonus(value, name); if (!convertVertices(bonus, ngb, hex)) { log.info("Not all vertices found"); *************** *** 121,125 **** public String toString() { StringBuffer s = new StringBuffer(); ! s.append("RevenueBonusTemplate with value " + value); s.append(", identVertices = " + identVertices); s.append(", identTrainTypes = " + identTrainTypes); --- 125,134 ---- public String toString() { StringBuffer s = new StringBuffer(); ! s.append("RevenueBonusTemplate"); ! if (name == null) ! s.append (" unnamed"); ! else ! s.append(" name = " + name); ! s.append(", value " + value); s.append(", identVertices = " + identVertices); s.append(", identTrainTypes = " + identTrainTypes); Index: RevenueBonus.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueBonus.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** RevenueBonus.java 11 May 2010 21:47:21 -0000 1.1 --- RevenueBonus.java 14 May 2010 15:19:57 -0000 1.2 *************** *** 17,20 **** --- 17,23 ---- private final int value; + // bonus name, also identifies mutually exclusive bonuses + private final String name; + // internal attributes private List<NetworkVertex> vertices; *************** *** 22,27 **** private List<PhaseI> phases; ! public RevenueBonus(int value) { this.value = value; vertices = new ArrayList<NetworkVertex>(); --- 25,31 ---- private List<PhaseI> phases; ! public RevenueBonus(int value, String name) { this.value = value; + this.name = name; vertices = new ArrayList<NetworkVertex>(); *************** *** 46,49 **** --- 50,57 ---- } + public String getName() { + return name; + } + public List<NetworkVertex> getVertices() { return vertices; *************** *** 62,69 **** --- 70,112 ---- } + public boolean addToRevenueCalculator(RevenueCalculator rc, int bonusId, List<NetworkVertex> allVertices, List<NetworkTrain> trains, PhaseI phase) { + if (isSimpleBonus() || !phases.isEmpty() && !phases.contains(phase)) return false; + // only non-simple bonuses and checks phase condition + + int[] verticesArray = new int[vertices.size()]; + for (int j=0; j < vertices.size(); j++) { + if (!allVertices.contains(vertices.get(j))) return false; // if vertex is not on graph, do not add bonus + verticesArray[j] = allVertices.indexOf(vertices.get(j)); + } + + boolean[] trainsArray = new boolean[trains.size()]; + for (int j=0; j < trains.size(); j++) { + trainsArray[j] = checkConditions(trains.get(j).getRailsTrainType(), phase); + } + + log.info("Add revenueBonus to RC, id = " + bonusId + ", bonus = " + this); + + rc.setBonus(bonusId, value, verticesArray, trainsArray); + + return true; + } + 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) { + if (!visitVertices.contains(vertex)) { + result = false; + break; + } + } + } + return result; + } + public boolean checkConditions(TrainTypeI trainType, PhaseI phase) { boolean result = true; *************** *** 88,96 **** return result; } ! @Override public String toString() { StringBuffer s = new StringBuffer(); ! s.append("RevenueBonus with value " + value); s.append(", vertices = " + vertices); s.append(", trainTypes = " + trainTypes); --- 131,144 ---- return result; } ! @Override public String toString() { StringBuffer s = new StringBuffer(); ! s.append("RevenueBonus"); ! if (name == null) ! s.append (" unnamed"); ! else ! s.append(" name = " + name); ! s.append(", value " + value); s.append(", vertices = " + vertices); s.append(", trainTypes = " + trainTypes); *************** *** 98,101 **** --- 146,158 ---- return s.toString(); } + + + public static int getNumberNonSimpleBonuses(List<RevenueBonus> bonuses) { + int number = 0; + for (RevenueBonus bonus:bonuses) { + if (!bonus.isSimpleBonus()) number++; + } + return number; + } } Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** RevenueAdapter.java 12 May 2010 18:50:26 -0000 1.12 --- RevenueAdapter.java 14 May 2010 15:19:57 -0000 1.13 *************** *** 6,13 **** --- 6,16 ---- import java.util.ArrayList; import java.util.Arrays; + import java.util.Collection; import java.util.Collections; import java.util.HashMap; + import java.util.HashSet; import java.util.List; import java.util.Map; + import java.util.Set; import org.apache.log4j.Logger; *************** *** 24,161 **** ! public class RevenueAdapter implements Runnable { protected static Logger log = Logger.getLogger(RevenueAdapter.class.getPackage().getName()); ! private GameManagerI gameManager; ! private NetworkGraphBuilder graphBuilder; ! private PublicCompanyI company; ! private PhaseI phase; ! private SimpleGraph<NetworkVertex, NetworkEdge> graph; ! ! private RevenueCalculator rc; ! private int maxNeighbors; ! private int maxBlocks; ! private List<NetworkVertex> vertexes; ! private List<NetworkEdge> edges; ! private List<NetworkVertex> startVertexes; private List<NetworkTrain> trains; ! private Map<NetworkVertex, List<NetworkVertex>> vertexVisitSets; private List<RevenueBonus> revenueBonuses; ! // revenue listener private RevenueListener revenueListener; ! public RevenueAdapter(GameManagerI gameManager, NetworkGraphBuilder graphBuilder, PublicCompanyI company){ this.gameManager = gameManager; this.graphBuilder = graphBuilder; ! this.graph = NetworkGraphBuilder.optimizeGraph(graphBuilder.getRailRoadGraph(company)); ! this.vertexes = new ArrayList<NetworkVertex>(graph.vertexSet()); ! this.edges = new ArrayList<NetworkEdge>(graph.edgeSet()); this.trains = new ArrayList<NetworkTrain>(); ! this.startVertexes = new ArrayList<NetworkVertex>(); ! this.vertexVisitSets = new HashMap<NetworkVertex, List<NetworkVertex>>(); this.revenueBonuses = new ArrayList<RevenueBonus>(); } ! private void defineRevenueBonuses() { ! // check each vertex hex for a potential revenue bonus ! for (NetworkVertex vertex:vertexes) { ! MapHex hex = vertex.getHex(); ! if (hex == null) continue; ! ! List<RevenueBonusTemplate> bonuses = new ArrayList<RevenueBonusTemplate>(); ! List<RevenueBonusTemplate> hexBonuses = hex.getRevenueBonuses(); ! if (hexBonuses != null) bonuses.addAll(hexBonuses); ! // List<RevenueBonusTemplate> tileBonuses = hex.getCurrentTile().getRevenueBonuses(); ! // if (tileBonuses != null) bonuses.addAll(hexBonuses); ! if (bonuses == null) continue; ! for (RevenueBonusTemplate bonus:bonuses) { ! revenueBonuses.add(bonus.toRevenueBonus(hex, gameManager, graphBuilder)); ! } } ! log.info("RevenueBonuses = " + revenueBonuses); } ! private int defineVertexVisitSets() { // define map of all locationNames ! Map<String, List<NetworkVertex>> locations = new HashMap<String, List<NetworkVertex>>(); ! for (NetworkVertex vertex:vertexes) { String ln = vertex.getCityName(); if (ln == null) continue; if (locations.containsKey(ln)) { ! locations.get(ln).add(vertex); } else { ! List<NetworkVertex> v = new ArrayList<NetworkVertex>(); ! v.add(vertex); locations.put(ln, v); } } log.info("Locations = " + locations); ! // transfer those locationNames to vertexBlocks ! int maxBlocks = 0; ! for (List<NetworkVertex> location:locations.values()) { ! if (location.size() >= 2) { ! for (NetworkVertex vertex:location){ ! if (vertexVisitSets.containsKey(vertex)) { ! for (NetworkVertex v:location) { ! if (v != vertex && !vertexVisitSets.get(vertex).contains(v)) { ! vertexVisitSets.get(vertex).add(v); ! } ! } ! } else { ! List<NetworkVertex> blocks = new ArrayList<NetworkVertex>(); ! for (NetworkVertex v:location) { ! if (v != vertex) { ! blocks.add(v); ! } ! } ! vertexVisitSets.put(vertex, blocks); ! } ! } ! maxBlocks = Math.max(maxBlocks, location.size()); } } - log.info("RA: Block of " + vertexVisitSets + ", maxBlocks = " + maxBlocks); - return maxBlocks; } ! public void initRevenueCalculator(){ ! if (rc == null) { ! // define blocks and return those ! maxBlocks = defineVertexVisitSets(); ! ! // define revenueBonuses ! defineRevenueBonuses(); ! // define the maximum number of vertexes ! maxNeighbors = 0; ! for (NetworkVertex vertex:vertexes) ! if (!vertex.isHQ()) ! maxNeighbors = Math.max(maxNeighbors, ! graph.edgesOf(vertex).size()); ! log.info("maxNeighbors = " + maxNeighbors); ! this.rc = new RevenueCalculator(this, vertexes.size(), edges.size(), maxNeighbors, maxBlocks, trains.size()); } } ! public void refreshRevenueCalculator() { ! rc = null; ! // refresh startVertexes ! this.startVertexes = new ArrayList<NetworkVertex>(); ! // refresh revenueBonuses ! this.revenueBonuses = new ArrayList<RevenueBonus>(); } ! private void prepareRevenuePrediction(boolean activatePrediction) { // separate vertexes List<NetworkVertex> cities = new ArrayList<NetworkVertex>(); List<NetworkVertex> towns = new ArrayList<NetworkVertex>(); ! for (NetworkVertex vertex: vertexes) { if (vertex.isMajor()) cities.add(vertex); if (vertex.isMinor()) towns.add(vertex); --- 27,289 ---- ! public final class RevenueAdapter implements Runnable { protected static Logger log = Logger.getLogger(RevenueAdapter.class.getPackage().getName()); ! // define VertexVisitSet ! public class VertexVisit { ! Set<NetworkVertex> set; ! VertexVisit() {set = new HashSet<NetworkVertex>();} ! public String toString() { ! return "VertexVisit Set:" + set; ! } ! } ! // basic links, to be defined at creation ! private final GameManagerI gameManager; ! private final NetworkGraphBuilder graphBuilder; ! private final PublicCompanyI company; ! private final PhaseI phase; ! ! // basic components, defined empty at creation ! private SimpleGraph<NetworkVertex, NetworkEdge> graph; ! private Set<NetworkVertex> startVertices; private List<NetworkTrain> trains; ! private List<VertexVisit> vertexVisitSets; private List<RevenueBonus> revenueBonuses; + private Set<NetworkVertex> protectedVertices; ! // components related to the revenue calculator ! private RevenueCalculator rc; ! SimpleGraph<NetworkVertex,NetworkEdge> rcGraph; ! private List<NetworkVertex> rcVertices; ! private List<NetworkEdge> rcEdges; ! private List<RevenueTrainRun> optimalRun; ! ! // revenue listener to communicate results private RevenueListener revenueListener; ! public RevenueAdapter(GameManagerI gameManager, NetworkGraphBuilder graphBuilder, PublicCompanyI company, PhaseI phase){ this.gameManager = gameManager; this.graphBuilder = graphBuilder; + this.company = company; + this.phase = phase; ! this.graph = new SimpleGraph<NetworkVertex, NetworkEdge>(NetworkEdge.class); this.trains = new ArrayList<NetworkTrain>(); ! this.startVertices = new HashSet<NetworkVertex>(); ! this.vertexVisitSets = new ArrayList<VertexVisit>(); this.revenueBonuses = new ArrayList<RevenueBonus>(); + this.protectedVertices = new HashSet<NetworkVertex>(); } ! public PhaseI getPhase() { ! return phase; ! } ! ! public Set<NetworkVertex> getVertices() { ! return graph.vertexSet(); ! } ! ! public Set<NetworkEdge> getEdges() { ! return graph.edgeSet(); ! } ! ! public SimpleGraph<NetworkVertex,NetworkEdge> getRCGraph() { ! return rcGraph; ! } ! ! public int getRCVertexId(NetworkVertex vertex) { ! return rcVertices.indexOf(vertex); ! } ! public int getRCEdgeId(NetworkEdge edge) { ! return rcEdges.indexOf(edge); ! } ! ! public Set<NetworkVertex> getStartVertices() { ! return startVertices; ! } ! ! public boolean addStartVertex(NetworkVertex startVertex) { ! if (startVertices.contains(startVertex)) return false; ! ! startVertices.add(startVertex); ! return true; ! } ! ! public List<NetworkTrain> getTrains() { ! return trains; ! } ! ! public boolean addTrain(TrainI railsTrain){ ! NetworkTrain train = NetworkTrain.createFromRailsTrain(railsTrain); ! if (train == null) { ! return false; ! } else { ! trains.add(train); ! return true; } ! } ! ! public boolean addTrainByString(String trainString) { ! TrainTypeI trainType = gameManager.getTrainManager().getTypeByName(trainString.trim()); ! if (trainType != null) { // string defines available trainType ! log.info("RA: found trainType" + trainType); ! TrainI railsTrain = trainType.cloneTrain(); ! return addTrain(railsTrain); ! } else { // otherwise interpret the train ! NetworkTrain train = NetworkTrain.createFromString(trainString); ! if (train == null) return false; ! trains.add(train); ! return true; ! } ! } ! ! public List<VertexVisit> getVertexVisitSets() { ! return vertexVisitSets; } ! public void addVertexVisitSet(VertexVisit visit) { ! vertexVisitSets.add(visit); ! protectedVertices.addAll(visit.set); ! } ! ! public List<RevenueBonus> getRevenueBonuses() { ! return revenueBonuses; ! } ! ! public void addRevenueBonus(RevenueBonus bonus) { ! revenueBonuses.add(bonus); ! protectedVertices.addAll(bonus.getVertices()); ! } ! ! public void populateFromRails() { ! // define graph, without HQ ! graph = graphBuilder.getRailRoadGraph(company, false); ! ! // define startVertexes ! startVertices.addAll(graphBuilder.getCompanyBaseTokenVertexes(company)); ! ! // define visit sets ! defineVertexVisitSets(); ! ! // define revenueBonuses ! defineRevenueBonuses(); ! ! // define Trains ! company.getPortfolio().getTrainList(); ! for (TrainI train:company.getPortfolio().getTrainList()) { ! addTrain(train); ! } ! ! } ! private void defineVertexVisitSets() { // define map of all locationNames ! Map<String, VertexVisit> locations = new HashMap<String, VertexVisit>(); ! for (NetworkVertex vertex:getVertices()) { String ln = vertex.getCityName(); if (ln == null) continue; if (locations.containsKey(ln)) { ! locations.get(ln).set.add(vertex); } else { ! VertexVisit v = new VertexVisit(); ! v.set.add(vertex); locations.put(ln, v); } } log.info("Locations = " + locations); ! // convert the location map to the vertex sets ! for (VertexVisit location:locations.values()) { ! if (location.set.size() >= 2) { ! addVertexVisitSet(location); } } } + + private void defineRevenueBonuses() { + // create set of all hexes + Set<MapHex> hexes = new HashSet<MapHex>(); + for (NetworkVertex vertex:getVertices()) { + MapHex hex = vertex.getHex(); + if (hex != null) hexes.add(hex); + } ! // check each vertex hex for a potential revenue bonus ! for (MapHex hex:hexes) { ! List<RevenueBonusTemplate> bonuses = new ArrayList<RevenueBonusTemplate>(); ! List<RevenueBonusTemplate> hexBonuses = hex.getRevenueBonuses(); ! if (hexBonuses != null) bonuses.addAll(hexBonuses); ! List<RevenueBonusTemplate> tileBonuses = hex.getCurrentTile().getRevenueBonuses(); ! if (tileBonuses != null) bonuses.addAll(tileBonuses); ! ! if (bonuses == null) continue; ! for (RevenueBonusTemplate bonus:bonuses) { ! addRevenueBonus(bonus.toRevenueBonus(hex, gameManager, graphBuilder)); ! } } + log.info("RA: RevenueBonuses = " + revenueBonuses); } + ! public void initRevenueCalculator(){ ! // optimize graph (optimizeGraph clones the graph) ! rcGraph = NetworkGraphBuilder.optimizeGraph(graph, protectedVertices); ! ! // define the vertices and edges lists ! rcVertices = new ArrayList<NetworkVertex>(rcGraph.vertexSet()); ! NetworkVertex.initAllRailsVertices(rcVertices, company, phase); ! // define ordering on vertexes by value ! Collections.sort(rcVertices, new NetworkVertex.ValueOrder()); ! rcEdges = new ArrayList<NetworkEdge>(rcGraph.edgeSet()); ! ! // prepare train length ! prepareTrainLengths(rcVertices); ! ! // check dimensions ! int maxVisitVertices = maxVisitVertices(); ! int maxBonusVertices = maxRevenueBonusVertices(); ! int maxNeighbors = maxVertexNeighbors(rcVertices); ! ! rc = new RevenueCalculator(this, rcVertices.size(), rcEdges.size(), ! maxNeighbors, maxVisitVertices, trains.size(), maxBonusVertices); ! ! populateRevenueCalculator(); ! } ! ! private int maxVisitVertices() { ! int maxNbVertices = 0; ! for (VertexVisit vertexVisit:vertexVisitSets) { ! maxNbVertices = Math.max(maxNbVertices, vertexVisit.set.size()); ! } ! log.info("RA: Block of " + vertexVisitSets + ", maximum vertices in a set = "+ maxNbVertices); ! return maxNbVertices; ! } ! ! ! private int maxVertexNeighbors(Collection<NetworkVertex> vertices) { ! int maxNeighbors = 0; ! for (NetworkVertex vertex:vertices) { ! maxNeighbors = Math.max(maxNeighbors, rcGraph.edgesOf(vertex).size()); ! } ! log.info("RA: Maximum neighbors in graph = "+ maxNeighbors); ! return maxNeighbors; ! } ! ! private int maxRevenueBonusVertices() { ! // get the number of non-simple bonuses ! int nbBonuses = RevenueBonus.getNumberNonSimpleBonuses(revenueBonuses); ! log.info("Number of non simple bonuses = " + nbBonuses); ! return nbBonuses; } ! private void prepareTrainLengths(Collection<NetworkVertex> vertices) { // separate vertexes List<NetworkVertex> cities = new ArrayList<NetworkVertex>(); List<NetworkVertex> towns = new ArrayList<NetworkVertex>(); ! for (NetworkVertex vertex: vertices) { if (vertex.isMajor()) cities.add(vertex); if (vertex.isMinor()) towns.add(vertex); *************** *** 181,204 **** } ! public void populateRevenueCalculator(PhaseI phase, boolean activatePrediction){ ! // store phase ! this.phase = phase; ! ! if (rc == null) initRevenueCalculator(); ! ! // prepare and optionally activate revenue prediction ! prepareRevenuePrediction(activatePrediction); ! ! // Define ordering on vertexes by value ! NetworkVertex.initAllRailsVertices(vertexes, company, phase); ! Collections.sort(vertexes, new NetworkVertex.ValueOrder()); ! for (int id=0; id < vertexes.size(); id++){ ! NetworkVertex v = vertexes.get(id); ! if (v.isHQ()) { ! // HQ is not added to list, but used to assign startVertexes ! startVertexes.addAll(Graphs.neighborListOf(graph, v)); ! continue; ! } // add to revenue calculator v.addToRevenueCalculator(rc, id); --- 309,316 ---- } ! private void populateRevenueCalculator(){ ! for (int id=0; id < rcVertices.size(); id++){ ! NetworkVertex v = rcVertices.get(id); // add to revenue calculator v.addToRevenueCalculator(rc, id); *************** *** 210,242 **** // set neighbors if (!v.isSink()) { ! List<NetworkVertex> neighbors = Graphs.neighborListOf(graph, v); int j=0, neighborsArray[] = new int[neighbors.size()]; for (NetworkVertex n:neighbors){ ! neighborsArray[j++] = vertexes.indexOf(n); } ! // sort by value order Arrays.sort(neighborsArray, 0, j); // define according edges int[] edgesArray = new int[j]; for (int e=0; e < j; e++) { ! NetworkVertex n = vertexes.get(neighborsArray[e]); ! edgesArray[e] = edges.indexOf(graph.getEdge(v, n)); } rc.setVertexNeighbors(id, neighborsArray, edgesArray); } - // set blocks - if (vertexVisitSets.containsKey(v)) { - int b = 0, blocks[] = new int[vertexVisitSets.get(v).size()]; - for (NetworkVertex n: vertexVisitSets.get(v)) { - blocks[b++] = vertexes.indexOf(n); - } - rc.setVertexVisitSets(id, blocks); - } } // set startVertexes ! int[] sv = new int[startVertexes.size()]; ! for (int j=0; j < startVertexes.size(); j++) { ! sv[j] = vertexes.lastIndexOf(startVertexes.get(j)); } Arrays.sort(sv); // sort by value order --- 322,346 ---- // 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); } } // set startVertexes ! int startVertexId =0, sv[] = new int[startVertices.size()]; ! for (NetworkVertex startVertex:startVertices) { ! sv[startVertexId++] = rcVertices.indexOf(startVertex); } Arrays.sort(sv); // sort by value order *************** *** 244,250 **** // set edges ! for (int id=0; id < edges.size(); id++) { // prepare values ! NetworkEdge e = edges.get(id); boolean greedy = e.isGreedy(); int distance = e.getDistance(); --- 348,354 ---- // set edges ! for (int id=0; id < rcEdges.size(); id++) { // prepare values ! NetworkEdge e = rcEdges.get(id); boolean greedy = e.isGreedy(); int distance = e.getDistance(); *************** *** 258,261 **** --- 362,381 ---- } + // set vertex sets + for (VertexVisit visit:vertexVisitSets) { + int j=0, setArray[] = new int[visit.set.size()]; + for (NetworkVertex n:visit.set){ + setArray[j++] = rcVertices.indexOf(n); + } + rc.setVisitSet(setArray); + } + + + log.info("rcVertices:" + rcVertices); + // set revenue bonuses + int id = 0; + for (RevenueBonus bonus:revenueBonuses) { + if (bonus.addToRevenueCalculator(rc, id, rcVertices, trains, phase)) id ++; + } } *************** *** 276,348 **** } ! public void addDefaultTrain(int cities) { ! String trainName = Integer.valueOf(cities).toString(); ! NetworkTrain train =new NetworkTrain(cities, 0, false, 1, 1, trainName, null); ! trains.add(train); ! } ! ! public void addTrain(TrainI railsTrain){ ! NetworkTrain train = NetworkTrain.createFromRailsTrain(railsTrain); ! if (train != null) trains.add(train); ! } ! ! public void addTrainByString(String trainString) { ! String t = trainString.trim(); ! TrainTypeI trainType = gameManager.getTrainManager().getTypeByName(trainString); ! if (trainType != null) { // string defines available trainType ! TrainI railsTrain = trainType.cloneTrain(); ! addTrain(railsTrain); ! log.info("RA: found trainType" + trainType); ! } else { // otherwise interpret the train ! int cities = 0; int towns = 0; boolean ignoreTowns = false; int multiplyCities = 1; int multiplyTowns = 1; ! if (t.equals("D")) { ! cities = 99; // diesel ! } else if (t.contains("+")) { ! cities = Integer.parseInt(t.split("\\+")[0]); // + train ! towns = Integer.parseInt(t.split("\\+")[1]); ! } else if (t.contains("E")) { ! // express train ! cities = Integer.parseInt(t.replace("E", "")); ! ignoreTowns = true; ! multiplyTowns = 0; ! } else if (t.contains("D")) { ! // double (express) train ! cities = Integer.parseInt(t.replace("D", "")); ! ignoreTowns = true; ! multiplyCities = 2; ! multiplyTowns = 0; ! } else { ! // default train ! cities = Integer.parseInt(t); } - NetworkTrain networkTrain = new NetworkTrain(cities, towns, ignoreTowns, multiplyCities, multiplyTowns, t, null); - trains.add(networkTrain); } } - public void addStartVertex(NetworkVertex v) { - startVertexes.add(v); - } - - public void addRevenueBonus(RevenueBonus bonus) { - revenueBonuses.add(bonus); - } ! public Map<NetworkTrain, List<NetworkVertex>> getOptimalRun() { ! int[][] optimalRunRaw = rc.getOptimalRun(); ! Map<NetworkTrain, List<NetworkVertex>> optimalRun = new HashMap<NetworkTrain, List<NetworkVertex>>(); ! for (int j=0; j < optimalRunRaw.length; j++) { ! List<NetworkVertex> runList = new ArrayList<NetworkVertex>(); ! for (int v=0; v < optimalRunRaw[j].length; v++) { ! int vertexId = optimalRunRaw[j][v]; if (vertexId == -1) break; ! runList.add(vertexes.get(vertexId)); } ! optimalRun.put(trains.get(j), runList); } ! return optimalRun; } - public int calculateRevenue() { return calculateRevenue(0, trains.size() - 1); --- 396,430 ---- } ! public String getVertexValueAsString(NetworkVertex vertex, NetworkTrain train, PhaseI phase) { ! StringBuffer s = new StringBuffer(); ! ! // base value ! s.append(vertex.getValueByTrain(train)); ! ! // add potential revenueBonuses ! for (RevenueBonus bonus:revenueBonuses) { ! if (bonus.checkSimpleBonus(vertex, train.getRailsTrainType(), phase)) { ! s.append("+" + bonus.getValue()); } } + return s.toString(); } ! private List<RevenueTrainRun> convertRcRun(int[][] rcRun) { ! ! List<RevenueTrainRun> convertRun = new ArrayList<RevenueTrainRun>(); ! for (int j=0; j < rcRun.length; j++) { ! RevenueTrainRun trainRun = new RevenueTrainRun(this, trains.get(j)); ! for (int v=0; v < rcRun[j].length; v++) { ! int vertexId = rcRun[j][v]; if (vertexId == -1) break; ! trainRun.addVertex(rcVertices.get(vertexId)); } ! convertRun.add(trainRun); } ! return convertRun; } public int calculateRevenue() { return calculateRevenue(0, trains.size() - 1); *************** *** 350,358 **** public int calculateRevenue(int startTrain, int finalTrain) { ! if (startTrain < 0 || finalTrain >= trains.size() || startTrain > finalTrain) return -1; rc.initialPredictionRuns(startTrain, finalTrain); ! return rc.calculateRevenue(startTrain, finalTrain); } - public void addRevenueListener(RevenueListener listener) { --- 432,447 ---- public int calculateRevenue(int startTrain, int finalTrain) { ! if (startTrain < 0 || finalTrain >= trains.size() || startTrain > finalTrain) { ! optimalRun = null; ! return 0; ! } rc.initialPredictionRuns(startTrain, finalTrain); ! int value = rc.calculateRevenue(startTrain, finalTrain); ! optimalRun = convertRcRun(rc.getOptimalRun()); ! return value; ! } ! public List<RevenueTrainRun> getOptimalRun() { ! return optimalRun; } public void addRevenueListener(RevenueListener listener) { *************** *** 382,417 **** public String getOptimalRunPrettyPrint() { StringBuffer runPrettyPrint = new StringBuffer(); ! Map<NetworkTrain, List<NetworkVertex>> run = getOptimalRun(); ! ! for (NetworkTrain train:run.keySet()) { ! runPrettyPrint.append("Train " + train + ": "); ! MapHex currentHex = null; ! NetworkVertex startVertex = null; ! for (NetworkVertex vertex:run.get(train)) { ! if (startVertex == null) { ! currentHex = vertex.getHex(); ! startVertex = vertex; ! runPrettyPrint.append(vertex.getHex().getName() + "("); ! } else if (startVertex == vertex) { ! currentHex = vertex.getHex(); ! runPrettyPrint.append(") / " + vertex.getHex().getName() + "(0"); ! continue; ! } else if (vertex.getHex() != currentHex) { ! currentHex = vertex.getHex(); ! runPrettyPrint.append("), " + vertex.getHex().getName() + "("); ! } else { ! runPrettyPrint.append(","); ! } ! if (vertex.isStation()) { ! runPrettyPrint.append(getVertexValue(vertex, train, phase)); ! } else { ! runPrettyPrint.append(currentHex.getOrientationName(vertex.getSide())); ! } ! } ! if (currentHex != null) { ! runPrettyPrint.append(")"); ! } ! runPrettyPrint.append("\n"); } return runPrettyPrint.toString(); --- 471,479 ---- public String getOptimalRunPrettyPrint() { + if (optimalRun == null) return "No Optimal Run"; + StringBuffer runPrettyPrint = new StringBuffer(); ! for (RevenueTrainRun run:optimalRun) { ! runPrettyPrint.append(run.prettyPrint()); } return runPrettyPrint.toString(); *************** *** 420,471 **** public void drawOptimalRunAsPath(HexMap map) { List<GeneralPath> pathList = new ArrayList<GeneralPath>(); ! Map<NetworkTrain, List<NetworkVertex>> run = getOptimalRun(); ! ! for (NetworkTrain train:run.keySet()) { ! GeneralPath path = new GeneralPath(); ! NetworkVertex startVertex = null; ! NetworkVertex previousVertex = null; ! for (NetworkVertex vertex:run.get(train)) { ! log.debug("RA: Next vertex " + vertex); ! Point2D vertexPoint = NetworkVertex.getVertexPoint2D(map, vertex); ! if (startVertex == null) { ! startVertex = vertex; ! previousVertex = vertex; ! path.moveTo((float)vertexPoint.getX(), (float)vertexPoint.getY()); ! continue; ! } else if (startVertex == vertex) { ! path.moveTo((float)vertexPoint.getX(), (float)vertexPoint.getY()); ! previousVertex = vertex; ! continue; ! } ! // draw hidden vertexes ! NetworkEdge edge = graph.getEdge(previousVertex, vertex); ! if (edge != null) { ! log.debug("RA: draw edge "+ edge.toFullInfoString()); ! List<NetworkVertex> hiddenVertexes = edge.getHiddenVertexes(); ! if (edge.getSource() == vertex) { ! log.debug("RA: reverse hiddenVertexes"); ! for (int i = hiddenVertexes.size() - 1; i >= 0; i--) { ! NetworkVertex v = hiddenVertexes.get(i); ! Point2D vPoint = NetworkVertex.getVertexPoint2D(map, v); ! if (vPoint != null) { ! path.lineTo((float)vPoint.getX(), (float)vPoint.getY()); ! } ! } ! } else { ! for (NetworkVertex v:hiddenVertexes) { ! Point2D vPoint = NetworkVertex.getVertexPoint2D(map, v); ! if (vPoint != null) { ! path.lineTo((float)vPoint.getX(), (float)vPoint.getY()); ! } ! } ! } ! } ! if (vertexPoint != null) { ! path.lineTo((float)vertexPoint.getX(), (float)vertexPoint.getY()); ! } ! previousVertex = vertex; } - pathList.add(path); } map.setTrainPaths(pathList); --- 482,489 ---- public void drawOptimalRunAsPath(HexMap map) { List<GeneralPath> pathList = new ArrayList<GeneralPath>(); ! if (optimalRun != null) { ! for (RevenueTrainRun run:optimalRun) { ! pathList.add(run.getAsPath(map)); } } map.setTrainPaths(pathList); *************** *** 475,484 **** public String toString() { StringBuffer buffer = new StringBuffer(); ! buffer.append("RevenueCalculator: \n" + rc); ! buffer.append("\n Vertexes: \n" + vertexes); ! buffer.append("\n Edges: \n" + edges); return buffer.toString(); } - } --- 493,502 ---- public String toString() { StringBuffer buffer = new StringBuffer(); ! buffer.append("RevenueCalculator:\n" + rc + "\n"); ! buffer.append("rcVertices:\n" + rcVertices + "\n"); ! buffer.append("rcEdges:\n" + rcEdges + "\n"); ! buffer.append("startVertices:" + startVertices); return buffer.toString(); } } Index: NetworkGraphBuilder.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/NetworkGraphBuilder.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** NetworkGraphBuilder.java 11 May 2010 21:47:21 -0000 1.9 --- NetworkGraphBuilder.java 14 May 2010 15:19:57 -0000 1.10 *************** *** 4,7 **** --- 4,8 ---- import java.awt.Rectangle; import java.util.ArrayList; + import java.util.Collection; import java.util.HashMap; import java.util.HashSet; *************** *** 29,33 **** import rails.game.BaseToken; import rails.game.City; - import rails.game.GameManagerI; import rails.game.MapHex; import rails.game.PublicCompanyI; --- 30,33 ---- *************** *** 153,157 **** } ! public SimpleGraph<NetworkVertex, NetworkEdge> getRailRoadGraph(PublicCompanyI company) { // set sinks on mapgraph --- 153,157 ---- } ! public SimpleGraph<NetworkVertex, NetworkEdge> getRailRoadGraph(PublicCompanyI company, boolean addHQ) { // set sinks on mapgraph *************** *** 165,174... [truncated message content] |
From: Stefan F. <ste...@us...> - 2010-05-14 15:20:05
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv8794/rails/game Modified Files: TileI.java Tile.java Log Message: Updated and refactored revenue calculation, added support for 1835 Index: TileI.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/TileI.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** TileI.java 4 Apr 2010 22:02:53 -0000 1.18 --- TileI.java 14 May 2010 15:19:57 -0000 1.19 *************** *** 5,8 **** --- 5,9 ---- import java.util.Map; + import rails.algorithms.RevenueBonusTemplate; import rails.util.Tag; *************** *** 69,71 **** --- 70,75 ---- public int getQuantity(); + + public List<RevenueBonusTemplate> getRevenueBonuses(); + } Index: Tile.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/Tile.java,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** Tile.java 11 May 2010 21:47:21 -0000 1.39 --- Tile.java 14 May 2010 15:19:57 -0000 1.40 *************** *** 6,9 **** --- 6,10 ---- import java.util.regex.Pattern; + import rails.algorithms.RevenueBonusTemplate; import rails.game.model.ModelObject; import rails.util.LocalText; *************** *** 83,86 **** --- 84,90 ---- private final ArrayList<MapHex> tilesLaid = new ArrayList<MapHex>(); + /** Storage of revenueBonus that are bound to the tile */ + protected List<RevenueBonusTemplate> revenueBonuses = null; + public Tile(Integer id) { this.id = id; *************** *** 269,273 **** } } ! } --- 273,286 ---- } } ! ! // revenue bonus ! List<Tag> bonusTags = setTag.getChildren("RevenueBonus"); ! if (bonusTags != null) { ! revenueBonuses = new ArrayList<RevenueBonusTemplate>(); ! for (Tag bonusTag:bonusTags) { ! revenueBonuses.add(new RevenueBonusTemplate(bonusTag)); ! } ! } ! } *************** *** 480,484 **** return quantity; } ! @Override public String toString() { --- 493,501 ---- return quantity; } ! ! public List<RevenueBonusTemplate> getRevenueBonuses() { ! return revenueBonuses; ! } ! @Override public String toString() { |
From: Stefan F. <ste...@us...> - 2010-05-14 15:20:05
|
Update of /cvsroot/rails/18xx/data/1835 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv8794/data/1835 Modified Files: TileSet.xml Map.xml Tiles.xml Log Message: Updated and refactored revenue calculation, added support for 1835 Index: TileSet.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1835/TileSet.xml,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TileSet.xml 5 Mar 2010 20:33:18 -0000 1.13 --- TileSet.xml 14 May 2010 15:19:57 -0000 1.14 *************** *** 190,193 **** <Tile id="219" quantity="2" /> <Tile id="220" quantity="1" /> ! <Tile id="221" quantity="1" /> </TileManager> --- 190,203 ---- <Tile id="219" quantity="2" /> <Tile id="220" quantity="1" /> ! <Tile id="221" quantity="1" > ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="0"/> <Vertex id="2"/> </RevenueBonus> ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="0"/> <Vertex id="3"/> </RevenueBonus> ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="0"/> <Vertex id="4"/> </RevenueBonus> ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="1"/> <Vertex id="2"/> </RevenueBonus> ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="1"/> <Vertex id="3"/> </RevenueBonus> ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="1"/> <Vertex id="4"/> </RevenueBonus> ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="5"/> <Vertex id="2"/> </RevenueBonus> ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="5"/> <Vertex id="3"/> </RevenueBonus> ! <RevenueBonus value="-10" name="Elbe"> <Vertex id="5"/> <Vertex id="4"/> </RevenueBonus> ! </Tile> </TileManager> Index: Map.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1835/Map.xml,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Map.xml 18 Apr 2010 12:47:37 -0000 1.11 --- Map.xml 14 May 2010 15:19:57 -0000 1.12 *************** *** 108,112 **** <Hex name="M17" tile="0" cost="50"/> <Hex name="M19" tile="-3" orientation="1"/> ! <Hex name="N4" tile="-901" orientation="5" value="0,50,0"/> <Hex name="N6" tile="-41"/> <Hex name="N8" tile="0" cost="70"/> --- 108,112 ---- <Hex name="M17" tile="0" cost="50"/> <Hex name="M19" tile="-3" orientation="1"/> ! <Hex name="N4" tile="-901" orientation="5" value="0,50,0" city="Elsas/Lothringen"/> <Hex name="N6" tile="-41"/> <Hex name="N8" tile="0" cost="70"/> Index: Tiles.xml =================================================================== RCS file: /cvsroot/rails/18xx/data/1835/Tiles.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Tiles.xml 1 May 2010 19:32:39 -0000 1.9 --- Tiles.xml 14 May 2010 15:19:57 -0000 1.10 *************** *** 92,97 **** </Tile> <Tile colour="yellow" id="-806" name="Berlin"> ! <Station id="city1" position="402" slots="1" type="City" value="30"/> ! <Station id="city2" position="001" slots="1" type="City" value="30"/> <Track from="city1" gauge="normal" to="side4"/> <Track from="city2" gauge="normal" to="side5"/> --- 92,97 ---- </Tile> <Tile colour="yellow" id="-806" name="Berlin"> ! <Station id="city1" position="402" slots="1" type="City" city="Berlin" value="30"/> ! <Station id="city2" position="001" slots="1" type="City" city="Berlin" value="30"/> <Track from="city1" gauge="normal" to="side4"/> <Track from="city2" gauge="normal" to="side5"/> |
From: Erik V. <ev...@us...> - 2010-05-13 09:51:42
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30729/rails/ui/swing Modified Files: ORUIManager.java Log Message: Fixed holes that allowed not specifying the exchanged train in a train exchange action. Index: ORUIManager.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORUIManager.java,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** ORUIManager.java 2 May 2010 17:32:04 -0000 1.71 --- ORUIManager.java 13 May 2010 09:51:32 -0000 1.72 *************** *** 1089,1093 **** List<String> oldTrainOptions = new ArrayList<String>(oldTrains.size()); ! String[] options = new String[oldTrains.size() + 1]; int jj = 0; for (int j = 0; j < oldTrains.size(); j++) { --- 1089,1093 ---- List<String> oldTrainOptions = new ArrayList<String>(oldTrains.size()); ! String[] options = new String[oldTrains.size()]; int jj = 0; for (int j = 0; j < oldTrains.size(); j++) { *************** *** 1103,1109 **** JOptionPane.QUESTION_MESSAGE, null, options, options[0]); ! int index = oldTrainOptions.indexOf(exchangedTrainName); ! if (index >= 0) { ! exchangedTrain = oldTrains.get(index); } } --- 1103,1115 ---- JOptionPane.QUESTION_MESSAGE, null, options, options[0]); ! if (exchangedTrainName != null) { ! int index = oldTrainOptions.indexOf(exchangedTrainName); ! if (index >= 0) { ! exchangedTrain = oldTrains.get(index); ! } ! } ! if (exchangedTrain == null) { ! // No valid train selected - cancel the buy action ! train = null; } } |
From: Erik V. <ev...@us...> - 2010-05-13 09:51:41
|
Update of /cvsroot/rails/18xx In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30729 Modified Files: LocalisedText.properties Log Message: Fixed holes that allowed not specifying the exchanged train in a train exchange action. Index: LocalisedText.properties =================================================================== RCS file: /cvsroot/rails/18xx/LocalisedText.properties,v retrieving revision 1.131 retrieving revision 1.132 diff -C2 -d -r1.131 -r1.132 *** LocalisedText.properties 8 May 2010 14:23:21 -0000 1.131 --- LocalisedText.properties 13 May 2010 09:51:32 -0000 1.132 *************** *** 312,315 **** --- 312,316 ---- noCost=no cost NoDumping=Cannot dump presidency + NoExchangedTrainSpecified=No exchanged train specified NoGameOptions=This game has no options NoIncomeForPreviousOperation={0} gets no income for {1}% {2} shares as precursors have operated |
From: Erik V. <ev...@us...> - 2010-05-13 09:51:40
|
Update of /cvsroot/rails/18xx/rails/game In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30729/rails/game Modified Files: OperatingRound.java Log Message: Fixed holes that allowed not specifying the exchanged train in a train exchange action. Index: OperatingRound.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/OperatingRound.java,v retrieving revision 1.128 retrieving revision 1.129 diff -C2 -d -r1.128 -r1.129 *** OperatingRound.java 7 May 2010 20:03:49 -0000 1.128 --- OperatingRound.java 13 May 2010 09:51:32 -0000 1.129 *************** *** 1645,1648 **** --- 1645,1660 ---- } } + + if (action.isForExchange()) { + if (exchangedTrain == null) { + errMsg = LocalText.getText("NoExchangedTrainSpecified"); + break; + } else if (operatingCompany.getPortfolio().getTrainOfType(exchangedTrain.getType()) == null) { + errMsg = LocalText.getText("CompanyDoesNotOwnTrain", + operatingCompany.getName(), + exchangedTrain.getName()); + break; + } + } stb = action.getSpecialProperty(); |
From: Erik V. <ev...@us...> - 2010-05-13 09:51:40
|
Update of /cvsroot/rails/18xx/rails/game/action In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30729/rails/game/action Modified Files: BuyTrain.java Log Message: Fixed holes that allowed not specifying the exchanged train in a train exchange action. Index: BuyTrain.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/action/BuyTrain.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** BuyTrain.java 30 Apr 2010 09:35:36 -0000 1.20 --- BuyTrain.java 13 May 2010 09:51:32 -0000 1.21 *************** *** 216,220 **** } else { b.append(" for any amount"); - if (pricePaid > 0) b.append(" - paid: ").append(Bank.format(pricePaid)); } if (specialProperty != null) { --- 216,219 ---- *************** *** 222,233 **** } if (isForExchange()) { ! b.append(forcedExchange ? " (forced exchange)" : " (exchanged)"); } ! if (presidentMustAddCash) b.append(" must add cash ").append(Bank.format(presidentCashToAdd)); ! else if (presidentMayAddCash) b.append(" may add cash up to ").append( Bank.format(presidentCashToAdd)); ! if (pricePaid > 0) b.append(" - paid: ").append(Bank.format(pricePaid)); return b.toString(); --- 221,237 ---- } if (isForExchange()) { ! b.append(forcedExchange ? " (forced exchange)" : " (exchange)"); } ! if (presidentMustAddCash) { b.append(" must add cash ").append(Bank.format(presidentCashToAdd)); ! } else if (presidentMayAddCash) { b.append(" may add cash up to ").append( Bank.format(presidentCashToAdd)); ! } ! if (acted) { ! b.append(" - paid: ").append(Bank.format(pricePaid)); ! if (addedCash > 0) b.append(" pres.cash added: "+Bank.format(addedCash)); ! if (exchangedTrain != null) b.append(" exchanged for "+exchangedTrain.getName()+"-train"); ! } return b.toString(); |
From: Stefan F. <ste...@us...> - 2010-05-12 18:50:35
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv7190/rails/algorithms Modified Files: RevenueCalculator.java RevenueAdapter.java Log Message: Some minor RC improvements Index: RevenueCalculator.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueCalculator.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RevenueCalculator.java 11 May 2010 21:47:21 -0000 1.11 --- RevenueCalculator.java 12 May 2010 18:50:26 -0000 1.12 *************** *** 9,12 **** --- 9,13 ---- private final int nbVertexes; private final int nbTrains; + private final int nbEdges; // static vertex data *************** *** 15,21 **** private final boolean[] vertexMinor; private final int[] vertexNbNeighbors; ! private final int[] vertexNbBlocks; private final int[][] vertexNeighbors; private final int[][] vertexVisitSets; --- 16,23 ---- private final boolean[] vertexMinor; private final int[] vertexNbNeighbors; ! private final int[] vertexNbVisitSets; private final int[][] vertexNeighbors; + private final int[][] vertexEdges; private final int[][] vertexVisitSets; *************** *** 24,32 **** // static edge data ! private final boolean[][] edgeGreedy; ! private final int[][] edgeDistance; // dynamic edge data ! private final boolean[][] edgeUsed; // static train data --- 26,34 ---- // static edge data ! private final boolean[] edgeGreedy; ! private final int[] edgeDistance; // dynamic edge data ! private final boolean[] edgeUsed; // static train data *************** *** 41,44 **** --- 43,47 ---- private final boolean[][] trainVisited; private final int[][] trainVertexStack; + private final int[][] trainEdgeStack; private final int[] trainStackPos; private final int [] trainBottomPos; *************** *** 63,67 **** private int countVisits; private int countEdges; ! private int nbEdges; private int nbEvaluations; private int nbPredictions; --- 66,70 ---- private int countVisits; private int countEdges; ! private int nbEdgesTravelled; private int nbEvaluations; private int nbPredictions; *************** *** 82,92 **** ! public RevenueCalculator (RevenueAdapter revenueAdapter, int nbVertexes, int maxNeighbors, int maxBlocks, int nbTrains) { ! log.info("RC defined: nbVertexes = " + nbVertexes + ", maxNeighbors = " + maxNeighbors + ", maxBlocks = " + maxBlocks + ", nbTrains = " + nbTrains); this.revenueAdapter = revenueAdapter; this.nbVertexes = nbVertexes; this.nbTrains = nbTrains; --- 85,96 ---- ! public RevenueCalculator (RevenueAdapter revenueAdapter, int nbVertexes, int nbEdges, int maxNeighbors, int maxBlocks, int nbTrains) { ! log.info("RC defined: nbVertexes = " + nbVertexes + ", nbEdges = " + nbEdges + ", maxNeighbors = " + maxNeighbors + ", maxBlocks = " + maxBlocks + ", nbTrains = " + nbTrains); this.revenueAdapter = revenueAdapter; this.nbVertexes = nbVertexes; + this.nbEdges = nbEdges; this.nbTrains = nbTrains; *************** *** 98,108 **** vertexMinor = new boolean[nbVertexes]; vertexNbNeighbors = new int[nbVertexes]; ! vertexNbBlocks = new int[nbVertexes]; ! vertexNeighbors = new int[nbVertexes][maxNeighbors]; vertexVisitSets = new int[nbVertexes][maxBlocks]; ! edgeGreedy = new boolean[nbVertexes][nbVertexes]; ! edgeDistance = new int[nbVertexes][nbVertexes]; ! edgeUsed = new boolean[nbVertexes][nbVertexes]; trainMaxMajors = new int[nbTrains]; --- 102,113 ---- vertexMinor = new boolean[nbVertexes]; vertexNbNeighbors = new int[nbVertexes]; ! vertexNbVisitSets = new int[nbVertexes]; ! vertexNeighbors = new int[nbVertexes][maxNeighbors]; ! vertexEdges = new int[nbVertexes][maxNeighbors]; vertexVisitSets = new int[nbVertexes][maxBlocks]; ! edgeGreedy = new boolean[nbEdges]; ! edgeDistance = new int[nbEdges]; ! edgeUsed = new boolean[nbEdges]; trainMaxMajors = new int[nbTrains]; *************** *** 115,118 **** --- 120,124 ---- trainVisited = new boolean[nbTrains][nbVertexes]; trainVertexStack = new int[nbTrains][nbVertexes]; + trainEdgeStack = new int[nbTrains][nbVertexes]; trainStackPos = new int[nbTrains]; trainBottomPos = new int[nbTrains]; *************** *** 129,133 **** // default neighbors && blocks vertexNbNeighbors[id] = 0; ! vertexNbBlocks[id] = 0; } --- 135,139 ---- // default neighbors && blocks vertexNbNeighbors[id] = 0; ! vertexNbVisitSets[id] = 0; } *************** *** 136,143 **** } ! void setVertexNeighbors(int id, int[] neighbors) { // copy neighbors for (int j=0; j < neighbors.length; j++) { vertexNeighbors[id][j] = neighbors[j]; } vertexNbNeighbors[id] = neighbors.length; --- 142,150 ---- } ! void setVertexNeighbors(int id, int[] neighbors, int[] edges) { // copy neighbors for (int j=0; j < neighbors.length; j++) { vertexNeighbors[id][j] = neighbors[j]; + vertexEdges[id][j] = edges[j]; } vertexNbNeighbors[id] = neighbors.length; *************** *** 150,154 **** vertexVisitSets[id][j] = blocks[j]; } ! vertexNbBlocks[id] = blocks.length; } --- 157,161 ---- vertexVisitSets[id][j] = blocks[j]; } ! vertexNbVisitSets[id] = blocks.length; } *************** *** 158,164 **** ! void setEdge(int vertexLo, int vertexHi, boolean greedy, int distance) { ! edgeGreedy[vertexLo][vertexHi] = greedy; ! edgeDistance[vertexLo][vertexHi] = distance; } --- 165,171 ---- ! void setEdge(int edgeId, boolean greedy, int distance) { ! edgeGreedy[edgeId] = greedy; ! edgeDistance[edgeId] = distance; } *************** *** 183,187 **** if (useRevenuePrediction) statistics.append(", " + nbPredictions + " predictions"); ! statistics.append(" and " + nbEdges + " edges travelled."); return statistics.toString(); } --- 190,194 ---- if (useRevenuePrediction) statistics.append(", " + nbPredictions + " predictions"); ! statistics.append(" and " + nbEdgesTravelled + " edges travelled."); return statistics.toString(); } *************** *** 237,251 **** if (startTrain > finalTrain) return; - - nbEvaluations = 0; nbPredictions = 0; nbEdges = 0; useRevenuePrediction = true; this.maxCumulatedTrainRevenues = new int[nbTrains]; ! initRevenueValues(startTrain, finalTrain); if (startTrain == finalTrain) return; // start prediction runs ! nbEvaluations = 0; nbPredictions = 0; nbEdges = 0; log.info("RC: start individual prediction Runs"); --- 244,256 ---- if (startTrain > finalTrain) return; useRevenuePrediction = true; this.maxCumulatedTrainRevenues = new int[nbTrains]; ! initRevenueValues(startTrain, finalTrain); if (startTrain == finalTrain) return; // start prediction runs ! nbEvaluations = 0; nbPredictions = 0; nbEdgesTravelled = 0; log.info("RC: start individual prediction Runs"); *************** *** 297,300 **** --- 302,308 ---- log.debug("RC: runTrain " + trainId); + // intialize value + trainCurrentValue[trainId] = 0; + // initialize lengths trainMajors[trainId] = trainMaxMajors[trainId]; *************** *** 304,307 **** --- 312,319 ---- trainStackPos[trainId] = 0; trainBottomPos[trainId] = 0; + + // check if the revenue is enough + if (useRevenuePrediction && predictRevenues(trainId)) + return; // try all startVertexes *************** *** 309,343 **** int vertexId = startVertexes[i]; log.debug("RC: Using startVertex nr. " + i + " for train " + trainId); ! ! // encounterVertex adds value and returns true if value vertex ! Terminated trainTerminated = Terminated.NotYet; ! boolean valueStation = encounterVertex(trainId, vertexId, true); ! if (valueStation) { ! // check usual train termination ! trainTerminated = trainTerminated(trainId); ! if (trainTerminated == Terminated.WithoutEvaluation || ! // trainTerminated == Terminated.NotYet && ! useRevenuePrediction && predictRevenues(trainId)) { // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); continue; } } ! ! // and all edges of it ! if (trainTerminated == Terminated.NotYet) { ! for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { ! int neighborId = vertexNeighbors[vertexId][j]; ! log.debug("RC: Testing Neighbor Nr. " + j + " of startVertex is " + neighborId); ! if (travelEdge(vertexId, neighborId, true)) { ! trainStartEdge[trainId] = j; // store edge ! nextVertex(trainId, neighborId, vertexId); ! } } } // no more edges to find - finalizeVertex(trainId, vertexId); encounterVertex(trainId, vertexId, false); // keep them on the visited vertex list to avoid route duplication --- 321,349 ---- int vertexId = startVertexes[i]; log.debug("RC: Using startVertex nr. " + i + " for train " + trainId); ! boolean stationVertex = encounterVertex(trainId, vertexId, true); ! if (stationVertex) { ! // train cannot terminate at start vertex ! if (useRevenuePrediction && predictRevenues(trainId)) { // cannot beat current best value => leave immediately encounterVertex(trainId, vertexId, false); + // but keep them on the visited vertex list to avoid route duplication + trainVisited[trainId][vertexId] = true; log.debug("RC: finished startVertex " + vertexId + " for train " +trainId); continue; } } ! ! // then try all edges of it ! for (int j = 0; j < vertexNbNeighbors[vertexId]; j++) { ! int neighborId = vertexNeighbors[vertexId][j]; ! log.debug("RC: Testing Neighbor Nr. " + j + " of startVertex is " + neighborId); ! int edgeId = vertexEdges[vertexId][j]; ! if (travelEdge(trainId, edgeId, true)) { ! trainStartEdge[trainId] = j; // store start edge ! nextVertex(trainId, neighborId, edgeGreedy[edgeId]); } } // no more edges to find encounterVertex(trainId, vertexId, false); // keep them on the visited vertex list to avoid route duplication *************** *** 346,349 **** --- 352,356 ---- } + // finished all tries for (int i=0; i < startVertexes.length; i++) { // remove all of them from the visited vertex list *************** *** 351,354 **** --- 358,364 ---- } + // allow that the train does not run at all + finalizeVertex(trainId, -1); + log.debug("RC: finishTrain " + trainId); } *************** *** 371,380 **** continue; } ! if (travelEdge(vertexId, neighborId, true)) { ! nextVertex(trainId, neighborId, vertexId); } } - // no more edges to find - // finalizeVertex(trainId); trainStackPos[trainId]--; // pull from stack --- 381,389 ---- continue; } ! int edgeId = vertexEdges[vertexId][j]; ! if (travelEdge(trainId, edgeId, true)) { ! nextVertex(trainId, neighborId, edgeGreedy[edgeId]); } } trainStackPos[trainId]--; // pull from stack *************** *** 386,399 **** * arrives at an unvisited vertex */ ! private void nextVertex(int trainId, int vertexId, int previousId) { // 1. encounterVertex adds value and returns true if value vertex Terminated trainTerminated = Terminated.NotYet; ! boolean valueStation = encounterVertex(trainId, vertexId, true); ! if (valueStation) { // check usual train termination trainTerminated = trainTerminated(trainId); if (trainTerminated == Terminated.WithoutEvaluation || - // trainTerminated == Terminated.NotYet && useRevenuePrediction && predictRevenues(trainId)) { // cannot beat current best value => leave immediately --- 395,407 ---- * arrives at an unvisited vertex */ ! private void nextVertex(int trainId, int vertexId, boolean previousGreedy) { // 1. encounterVertex adds value and returns true if value vertex Terminated trainTerminated = Terminated.NotYet; ! boolean stationVertex = encounterVertex(trainId, vertexId, true); ! if (stationVertex) { // check usual train termination trainTerminated = trainTerminated(trainId); if (trainTerminated == Terminated.WithoutEvaluation || useRevenuePrediction && predictRevenues(trainId)) { // cannot beat current best value => leave immediately *************** *** 413,422 **** continue; } ! if (travelEdge(vertexId, neighborId, edgeGreedy[previousId][vertexId])) { ! nextVertex(trainId, neighborId, vertexId); } } // 2b. restart at startVertex for bottom part ! if (valueStation && trainBottomPos[trainId] == 0){ runBottom(trainId); } --- 421,431 ---- continue; } ! int edgeId = vertexEdges[vertexId][j]; ! if (travelEdge(trainId, edgeId, previousGreedy)) { ! nextVertex(trainId, neighborId, edgeGreedy[edgeId]); } } // 2b. restart at startVertex for bottom part ! if (stationVertex && trainBottomPos[trainId] == 0){ runBottom(trainId); } *************** *** 424,428 **** // 3. no more edges to visit from here => evaluate or start new train ! if (valueStation) finalizeVertex(trainId, vertexId); --- 433,437 ---- // 3. no more edges to visit from here => evaluate or start new train ! if (stationVertex) finalizeVertex(trainId, vertexId); *************** *** 439,474 **** trainVisited[trainId][vertexId] = arrive; ! boolean valueVertex; if (arrive) { ! if (vertexValueByTrain[vertexId][trainId] == 0) { ! valueVertex = false; ! } else { ! valueVertex = true; ! trainCurrentValue[trainId] += vertexValueByTrain[vertexId][trainId]; ! } ! if (vertexMajor[vertexId]) trainMajors[trainId]--; ! if (vertexMinor[vertexId]) { trainMinors[trainId]--; } trainVertexStack[trainId][trainStackPos[trainId]++] = vertexId; // push to stack countVisits++; } else { ! if (vertexValueByTrain[vertexId][trainId] == 0) { ! valueVertex = false; ! } else { ! valueVertex = true; ! trainCurrentValue[trainId] -= vertexValueByTrain[vertexId][trainId]; ! } ! if (vertexMajor[vertexId]) trainMajors[trainId]++; ! if (vertexMinor[vertexId]) trainMinors[trainId]++; trainStackPos[trainId]--; // pull from stack countVisits--; } ! // check blocks ! for (int j=0; j < vertexNbBlocks[vertexId]; j++) { if (vertexVisitSets[vertexId][j] != -1) { trainVisited[trainId][vertexVisitSets[vertexId][j]] = arrive; --- 448,478 ---- trainVisited[trainId][vertexId] = arrive; ! boolean stationVertex = false; if (arrive) { ! trainCurrentValue[trainId] += vertexValueByTrain[vertexId][trainId]; ! if (vertexMajor[vertexId]) { trainMajors[trainId]--; ! stationVertex = true; ! } else if (vertexMinor[vertexId]) { trainMinors[trainId]--; + stationVertex = !trainIgnoreMinors[trainId]; } trainVertexStack[trainId][trainStackPos[trainId]++] = vertexId; // push to stack countVisits++; } else { ! trainCurrentValue[trainId] -= vertexValueByTrain[vertexId][trainId]; ! if (vertexMajor[vertexId]) { trainMajors[trainId]++; ! stationVertex = true; ! } else if (vertexMinor[vertexId]) { trainMinors[trainId]++; + stationVertex = !trainIgnoreMinors[trainId]; + } trainStackPos[trainId]--; // pull from stack countVisits--; } ! // check vertex sets ! for (int j=0; j < vertexNbVisitSets[vertexId]; j++) { if (vertexVisitSets[vertexId][j] != -1) { trainVisited[trainId][vertexVisitSets[vertexId][j]] = arrive; *************** *** 478,497 **** log.debug("RC: Count Visits = " + countVisits); ! return valueVertex; } ! private boolean travelEdge(int startVertex, int endVertex, boolean previousGreedy) { ! if (edgeUsed[startVertex][endVertex]) { ! log.debug("RC: Edge from " + startVertex + " to " + endVertex + " already used" ); return false; ! } else if (previousGreedy || edgeGreedy[startVertex][endVertex]) { ! log.debug("RC: Travel edge from " + startVertex + " to " + endVertex ); ! edgeUsed[startVertex][endVertex] = true; ! edgeUsed[endVertex][startVertex] = true; ! countEdges++; nbEdges++; log.debug("RC: Count Edges = " + countEdges); return true; } else { ! log.debug("RC: Cannot travel from " + startVertex + " to " + endVertex + ", because of greedy rule"); return false; } --- 482,501 ---- log.debug("RC: Count Visits = " + countVisits); ! return stationVertex; } ! private boolean travelEdge(int trainId, int edgeId, boolean previousGreedy) { ! if (edgeUsed[edgeId]) { ! log.debug("RC: Edge id " + edgeId + " already used" ); return false; ! } else if (previousGreedy || edgeGreedy[edgeId]) { ! log.debug("RC: Travel edge id " + edgeId); ! edgeUsed[edgeId] = true; ! trainEdgeStack[trainId][trainStackPos[trainId]] = edgeId; ! countEdges++; nbEdgesTravelled++; log.debug("RC: Count Edges = " + countEdges); return true; } else { ! log.debug("RC: Cannot travel edge id " + edgeId + ", because of greedy rule"); return false; } *************** *** 511,525 **** } ! int startVertex = trainVertexStack[trainId][stackPos]; ! int endVertex = trainVertexStack[trainId][stackPos - 1]; ! if (edgeUsed[startVertex][endVertex]) { ! edgeUsed[startVertex][endVertex] = false; ! edgeUsed[endVertex][startVertex] = false; countEdges--; ! log.debug("RC: Cleared edge from " + startVertex + " to " + endVertex); log.debug("RC: Count Edges = " + countEdges); } else { ! log.debug ("RC: Error return edge not used: " + startVertex + " to " + endVertex); } } --- 515,527 ---- } ! int edgeId = trainEdgeStack[trainId][stackPos]; ! if (edgeUsed[edgeId]) { ! edgeUsed[edgeId] = false; countEdges--; ! log.debug("RC: Cleared edge id " + edgeId); log.debug("RC: Count Edges = " + countEdges); } else { ! log.debug ("RC: Error return edge id used: " + edgeId); } } *************** *** 545,549 **** private void finalizeVertex(int trainId, int vertexId) { ! log.debug("RC: No more edges found at " + vertexId + " for train " + trainId); if (trainId == finalTrain) { --- 547,551 ---- private void finalizeVertex(int trainId, int vertexId) { ! log.debug("RC: Finalize Vertex id " + vertexId + " for train " + trainId); if (trainId == finalTrain) { *************** *** 558,568 **** int totalValue = 0; for (int j = startTrain; j <= finalTrain; j++) { ! if (trainIgnoreMinors[j]) { ! if (trainMaxMajors[j] - trainMajors[j] >= 2) ! totalValue += trainCurrentValue[j]; ! } else { ! if (trainMaxMajors[j] + trainMaxMinors[j] - trainMajors[j] - trainMinors[j] >= 2) ! totalValue += trainCurrentValue[j]; ! } } --- 560,571 ---- int totalValue = 0; for (int j = startTrain; j <= finalTrain; j++) { ! totalValue += trainCurrentValue[j]; ! // if (trainIgnoreMinors[j]) { ! // if (trainMaxMajors[j] - trainMajors[j] >= 2) ! // totalValue += trainCurrentValue[j]; ! // } else { ! // if (trainMaxMajors[j] + trainMaxMinors[j] - trainMajors[j] - trainMinors[j] >= 2) ! // totalValue += trainCurrentValue[j]; ! // } } *************** *** 583,590 **** } } log.info("RC: Found better run with " + totalValue); // inform revenue listener via adapter notifyRevenueAdapter(currentBestValue, false); - } } } --- 586,593 ---- } } + } log.info("RC: Found better run with " + totalValue); // inform revenue listener via adapter notifyRevenueAdapter(currentBestValue, false); } } *************** *** 618,628 **** // and add the past trains: current realized values for (int j = startTrain; j < trainId; j++) { ! if (trainIgnoreMinors[j]) { ! if (trainMaxMajors[j] - trainMajors[j] >= 2) ! totalValue += trainCurrentValue[j]; ! } else { ! if (trainMaxMajors[j] + trainMaxMinors[j] - trainMajors[j] - trainMinors[j] >= 2) ! totalValue += trainCurrentValue[j]; ! } } --- 621,632 ---- // and add the past trains: current realized values for (int j = startTrain; j < trainId; j++) { ! totalValue += trainCurrentValue[j]; ! // if (trainIgnoreMinors[j]) { ! // if (trainMaxMajors[j] - trainMajors[j] >= 2) ! // totalValue += trainCurrentValue[j]; ! // } else { ! // if (trainMaxMajors[j] + trainMaxMinors[j] - trainMajors[j] - trainMinors[j] >= 2) ! // totalValue += trainCurrentValue[j]; ! // } } *************** *** 643,649 **** buffer.append("vertexMajor:" + Arrays.toString(vertexMajor) + "\n"); buffer.append("vertexMinor:" + Arrays.toString(vertexMinor) + "\n"); ! buffer.append("vertexEdges:" + Arrays.deepToString(vertexNeighbors) + "\n"); ! // buffer.append("edgeGreedy:" + Arrays.deepToString(edgeGreedy)); ! // buffer.append("edgeDistance:" + Arrays.deepToString(edgeDistance)); buffer.append("startVertexes:" + Arrays.toString(startVertexes) + "\n"); buffer.append("trainMaxMajors:" + Arrays.toString(trainMaxMajors) + "\n"); --- 647,654 ---- buffer.append("vertexMajor:" + Arrays.toString(vertexMajor) + "\n"); buffer.append("vertexMinor:" + Arrays.toString(vertexMinor) + "\n"); ! buffer.append("vertexNeighbors:" + Arrays.deepToString(vertexNeighbors) + "\n"); ! buffer.append("vertexEdges:" + Arrays.deepToString(vertexEdges) + "\n"); ! buffer.append("edgeGreedy:" + Arrays.toString(edgeGreedy) + "\n"); ! buffer.append("edgeDistance:" + Arrays.toString(edgeDistance) + "\n"); buffer.append("startVertexes:" + Arrays.toString(startVertexes) + "\n"); buffer.append("trainMaxMajors:" + Arrays.toString(trainMaxMajors) + "\n"); Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RevenueAdapter.java 12 May 2010 09:18:10 -0000 1.11 --- RevenueAdapter.java 12 May 2010 18:50:26 -0000 1.12 *************** *** 140,144 **** graph.edgesOf(vertex).size()); log.info("maxNeighbors = " + maxNeighbors); ! this.rc = new RevenueCalculator(this, vertexes.size(), maxNeighbors, maxBlocks, trains.size()); } } --- 140,144 ---- graph.edgesOf(vertex).size()); log.info("maxNeighbors = " + maxNeighbors); ! this.rc = new RevenueCalculator(this, vertexes.size(), edges.size(), maxNeighbors, maxBlocks, trains.size()); } } *************** *** 217,221 **** // sort by value order Arrays.sort(neighborsArray, 0, j); ! rc.setVertexNeighbors(id, neighborsArray); } // set blocks --- 217,227 ---- // sort by value order Arrays.sort(neighborsArray, 0, j); ! // define according edges ! int[] edgesArray = new int[j]; ! for (int e=0; e < j; e++) { ! NetworkVertex n = vertexes.get(neighborsArray[e]); ! edgesArray[e] = edges.indexOf(graph.getEdge(v, n)); ! } ! rc.setVertexNeighbors(id, neighborsArray, edgesArray); } // set blocks *************** *** 241,252 **** // prepare values NetworkEdge e = edges.get(id); - int vA = vertexes.lastIndexOf(e.getSource()); - int vB = vertexes.lastIndexOf(e.getTarget()); boolean greedy = e.isGreedy(); int distance = e.getDistance(); ! rc.setEdge(vA, vB, ! greedy, distance); ! rc.setEdge(vB, vA, ! greedy, distance); } --- 247,253 ---- // prepare values NetworkEdge e = edges.get(id); boolean greedy = e.isGreedy(); int distance = e.getDistance(); ! rc.setEdge(id, greedy, distance); } |
From: Stefan F. <ste...@us...> - 2010-05-12 09:18:18
|
Update of /cvsroot/rails/18xx/rails/algorithms In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv20829/rails/algorithms Modified Files: RevenueAdapter.java Log Message: Removed use of Java 1.6 method Index: RevenueAdapter.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/algorithms/RevenueAdapter.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** RevenueAdapter.java 11 May 2010 21:47:21 -0000 1.10 --- RevenueAdapter.java 12 May 2010 09:18:10 -0000 1.11 *************** *** 216,221 **** } // sort by value order ! neighborsArray = Arrays.copyOfRange(neighborsArray, 0, j); ! Arrays.sort(neighborsArray); rc.setVertexNeighbors(id, neighborsArray); } --- 216,220 ---- } // sort by value order ! Arrays.sort(neighborsArray, 0, j); rc.setVertexNeighbors(id, neighborsArray); } |
From: Erik V. <ev...@us...> - 2010-05-11 22:29:03
|
Update of /cvsroot/rails/18xx/rails/game/specific/_1856 In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv30354/rails/game/specific/_1856 Modified Files: PublicCompany_CGR.java Log Message: Fixed double withholding of CGR in 1856 Index: PublicCompany_CGR.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/game/specific/_1856/PublicCompany_CGR.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PublicCompany_CGR.java 27 Mar 2010 18:27:08 -0000 1.10 --- PublicCompany_CGR.java 11 May 2010 19:57:47 -0000 1.11 *************** *** 92,96 **** @Override public void withhold(int amount) { - if (amount > 0) new CashMove(bank, this, amount); if (hasStockPrice && canSharePriceVary.booleanValue()) { stockMarket.withhold(this); --- 92,95 ---- |
From: Stefan F. <ste...@us...> - 2010-05-11 21:47:30
|
Update of /cvsroot/rails/18xx/rails/ui/swing In directory sfp-cvsdas-4.v30.ch3.sourceforge.com:/tmp/cvs-serv14662/rails/ui/swing Modified Files: ORPanel.java Log Message: Added VertexVisitedSets and RevenueBonuses, several other improvements to the RC Index: ORPanel.java =================================================================== RCS file: /cvsroot/rails/18xx/rails/ui/swing/ORPanel.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** ORPanel.java 1 May 2010 16:07:05 -0000 1.61 --- ORPanel.java 11 May 2010 21:47:21 -0000 1.62 *************** *** 4,8 **** import java.awt.*; import java.awt.event.*; - import java.awt.geom.GeneralPath; import java.util.List; --- 4,7 ---- *************** *** 11,15 **** import org.apache.log4j.Logger; - import org.jgrapht.Graph; import org.jgrapht.graph.SimpleGraph; --- 10,13 ---- *************** *** 19,23 **** import rails.game.action.*; import rails.ui.swing.elements.*; - import rails.ui.swing.hexmap.HexMap; import rails.util.LocalText; import rails.util.Util; --- 17,20 ---- *************** *** 604,624 **** CompanyManagerI cm = gm.getCompanyManager(); PublicCompanyI company = cm.getPublicCompany(companyName); ! SimpleGraph<NetworkVertex, NetworkEdge> graph = nwGraph.getRailRoadGraph(company); ! ! // NetworkGraphBuilder.visualize(graph, "Network of " + companyName); ! graph = NetworkGraphBuilder.optimizeGraph(graph); ! // NetworkGraphBuilder.visualize(graph, "Optimized Network of " + companyName); ! ! // revenue calculation example on mapGraph ! // mapGraph = NetworkGraphBuilder.optimizeGraph(mapGraph); ! // RevenueAdapter ra = new RevenueAdapter(mapGraph); ! // // set tokens ! // List<TokenI> tokens = company.getTokens(); ! // for (TokenI token:tokens){ ! // NetworkVertex vertex = nwGraph.getVertex(token); ! // if (vertex != null) ra.addStartVertex(vertex); ! // } ! // run on railroad graph ! RevenueAdapter ra = new RevenueAdapter(graph); // get trains --- 601,605 ---- CompanyManagerI cm = gm.getCompanyManager(); PublicCompanyI company = cm.getPublicCompany(companyName); ! RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company); // get trains *************** *** 643,655 **** // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), true); ! ra.populateRevenueCalculator(company, gm.getCurrentPhase(), true); log.info("Revenue Adapter:" + ra); revenueValue = ra.calculateRevenue(); log.info("Revenue Value:" + revenueValue); ! log.info("Revenue run:" + ra.getOptimalRunPrettyPrint()); ra.drawOptimalRunAsPath(orUIManager.getMap()); orUIManager.getMap().repaint(); ! JOptionPane.showMessageDialog(orWindow, "With Prediction: RevenueValue = " + revenueValue + ! "\n RevenueRun = " + ra.getOptimalRunPrettyPrint()); String trainsToAdd = --- 624,636 ---- // ra.populateRevenueCalculator(company, gm.getPhaseManager().getPhaseByName("8"), true); ! ra.populateRevenueCalculator(gm.getCurrentPhase(), true); log.info("Revenue Adapter:" + ra); revenueValue = ra.calculateRevenue(); log.info("Revenue Value:" + revenueValue); ! log.info("Revenue Run:" + ra.getOptimalRunPrettyPrint()); ra.drawOptimalRunAsPath(orUIManager.getMap()); orUIManager.getMap().repaint(); ! JOptionPane.showMessageDialog(orWindow, "RevenueValue = " + revenueValue + ! "\nRevenueRun = \n" + ra.getOptimalRunPrettyPrint()); String trainsToAdd = *************** *** 840,846 **** // run on railroad graph, does not work so far, thus use map graph ! SimpleGraph<NetworkVertex, NetworkEdge> graph = nwGraph.getRailRoadGraph(company); ! graph = NetworkGraphBuilder.optimizeGraph(graph); ! RevenueAdapter ra = new RevenueAdapter(graph); // get trains --- 821,825 ---- // run on railroad graph, does not work so far, thus use map graph ! RevenueAdapter ra = new RevenueAdapter(gm, nwGraph, company); // get trains *************** *** 850,854 **** } ! ra.populateRevenueCalculator(company, gm.getCurrentPhase(), true); ra.addRevenueListener(this); --- 829,833 ---- } ! ra.populateRevenueCalculator(gm.getCurrentPhase(), true); ra.addRevenueListener(this); |