Changeset 25dc5ff34167fc62df39f2b19eec0406b2dc7690
- Timestamp:
- 11/03/07 10:57:45
(1 year ago)
- Author:
- Christopher Jung <bktheg@web.de>
- git-committer:
- Christopher Jung <bktheg@web.de> 1194083865 +0100
- git-parent:
[f082126a9f1dc7b76a2f6e356719d06f76b9a94b]
- git-author:
- Christopher Jung <bktheg@web.de> 1194083865 +0100
- Message:
Kleinere Korrekturen am JN-Router
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| refe50c3 |
r25dc5ff |
|
| 45 | 45 | */ |
|---|
| 46 | 46 | public List<SQLResultRow> path = new ArrayList<SQLResultRow>(); |
|---|
| | 47 | |
|---|
| | 48 | @Override |
|---|
| | 49 | public String toString() { |
|---|
| | 50 | StringBuilder builder = new StringBuilder("[distance: "+distance+"\npath: "); |
|---|
| | 51 | for( int i=0; i < path.size(); i++ ) { |
|---|
| | 52 | SQLResultRow pathElem = path.get(i); |
|---|
| | 53 | builder.append(pathElem.getInt("system")+":"+pathElem.getInt("x")+"/"+pathElem.getInt("y")+" -> "+pathElem.getInt("systemout")+":"+pathElem.getInt("xout")+"/"+pathElem.getInt("yout")+"\n"); |
|---|
| | 54 | } |
|---|
| | 55 | |
|---|
| | 56 | builder.append("]"); |
|---|
| | 57 | return builder.toString(); |
|---|
| | 58 | } |
|---|
| 47 | 59 | } |
|---|
| 48 | 60 | |
|---|
| … | … | |
| 61 | 73 | } |
|---|
| 62 | 74 | |
|---|
| | 75 | private int getMovementCost(int startX, int startY, int targetX, int targetY) { |
|---|
| | 76 | return Math.max(Math.abs(targetX-startX),Math.abs(targetY-startY)); |
|---|
| | 77 | } |
|---|
| | 78 | |
|---|
| 63 | 79 | /** |
|---|
| 64 | 80 | * Findet den kuerzesten Weg zwischen zwei Punkten |
|---|
| … | … | |
| 71 | 87 | * @return Der Pfad oder <code>null</code> |
|---|
| 72 | 88 | */ |
|---|
| 73 | | public Result locateShortestJNPath( int currentsys, int currentx, int currenty, int targetsys, int targetx, int targety) { |
|---|
| 74 | | if( !jnlist.containsKey(currentsys) ) { |
|---|
| 75 | | return null; |
|---|
| 76 | | } |
|---|
| 77 | | |
|---|
| | 89 | public Result locateShortestJNPath( int currentsys, int currentx, int currenty, int targetsys, int targetx, int targety) { |
|---|
| 78 | 90 | if( currentsys == targetsys ) { |
|---|
| 79 | 91 | Result res = new Result(); |
|---|
| 80 | 92 | res.distance = Math.max(Math.abs(targetx-currentx),Math.abs(targety-currenty)); |
|---|
| 81 | 93 | return res; |
|---|
| | 94 | } |
|---|
| | 95 | |
|---|
| | 96 | if( !jnlist.containsKey(currentsys) ) { |
|---|
| | 97 | return null; |
|---|
| 82 | 98 | } |
|---|
| 83 | 99 | |
|---|
| … | … | |
| 91 | 107 | continue; |
|---|
| 92 | 108 | } |
|---|
| 93 | | int pathcost = Math.max(Math.abs(ajn.getInt("x")-currentx),Math.abs(ajn.getInt("y")-currenty)); |
|---|
| | 109 | int pathcost = getMovementCost(currentx, currenty, ajn.getInt("x"), ajn.getInt("y")); |
|---|
| 94 | 110 | |
|---|
| | 111 | // JN vorlaeufig aus der Liste entfernen um Endlosschleifen zu vermeiden |
|---|
| 95 | 112 | sysJNList.remove(k); |
|---|
| 96 | | k--; |
|---|
| 97 | 113 | |
|---|
| 98 | 114 | Result cost = locateShortestJNPath(ajn.getInt("systemout"),ajn.getInt("xout"),ajn.getInt("yout"), targetsys, targetx, targety ); |
|---|
| | 115 | |
|---|
| | 116 | sysJNList.add(k, ajn); |
|---|
| | 117 | |
|---|
| | 118 | // Keine Route gefunden -> JN-Zielsystem ignorieren |
|---|
| 99 | 119 | if( cost == null ) { |
|---|
| 100 | 120 | if( !systemInterestLevel.containsKey(ajn.getInt("systemout")) ) { |
|---|
| … | … | |
| 103 | 123 | continue; |
|---|
| 104 | 124 | } |
|---|
| | 125 | // Erste moegliche Route gefunden |
|---|
| 105 | 126 | else if( shortestpath == null ) { |
|---|
| 106 | 127 | shortestpath = cost; |
|---|
| … | … | |
| 108 | 129 | shortestpath.path.add(0, ajn); |
|---|
| 109 | 130 | } |
|---|
| | 131 | // Neue Route mit der alten Route vergleichen |
|---|
| 110 | 132 | else if( shortestpath.distance > cost.distance+pathcost ) { |
|---|
| 111 | 133 | shortestpath = cost; |
|---|
| … | … | |
| 113 | 135 | shortestpath.path.add(0, ajn); |
|---|
| 114 | 136 | } |
|---|
| | 137 | |
|---|
| | 138 | // JN-Zielsystem bietet gueltige Route -> merken! |
|---|
| 115 | 139 | if( !systemInterestLevel.containsKey(ajn.getInt("systemout")) ) { |
|---|
| 116 | 140 | systemInterestLevel.put(ajn.getInt("systemout"), 1); |
|---|
| 117 | 141 | } |
|---|
| 118 | 142 | } |
|---|
| 119 | | |
|---|
| | 143 | |
|---|
| 120 | 144 | return shortestpath; |
|---|
| 121 | 145 | } |
|---|