Revision 14780
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/core/GvNode.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
import java.util.ArrayList; |
44 | 44 |
|
45 |
import edu.uci.ics.jung.graph.predicates.IsolatedVertexPredicate; |
|
46 |
|
|
45 | 47 |
public class GvNode { |
46 | 48 |
public final static int statNotInList = 0; |
47 | 49 |
public final static int statNowInList = 1; |
... | ... | |
70 | 72 |
} |
71 | 73 |
|
72 | 74 |
public void initialize() { |
73 |
numSoluc = AbstractNetSolver.numSolucGlobal;
|
|
75 |
numSoluc = GlobalCounter.numSolucGlobal;
|
|
74 | 76 |
from_link = -1; |
75 | 77 |
best_cost = Double.MAX_VALUE; |
76 | 78 |
stimation = Double.MAX_VALUE; |
... | ... | |
98 | 100 |
this.y = y; |
99 | 101 |
} |
100 | 102 |
public double getBestCost() { |
103 |
if (numSoluc != GlobalCounter.getGlobalSolutionNumber()) |
|
104 |
return Double.MAX_VALUE; |
|
101 | 105 |
return best_cost; |
102 | 106 |
} |
103 | 107 |
public void setBestCost(double best_cost) { |
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/core/GlobalCounter.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.graph.core; |
|
2 |
|
|
3 |
/** |
|
4 |
* @author fjp |
|
5 |
* Used inside nodes to avoid initialization of the whole network |
|
6 |
* |
|
7 |
*/ |
|
8 |
public class GlobalCounter { |
|
9 |
static int numSolucGlobal = 0; |
|
10 |
|
|
11 |
public static int getGlobalSolutionNumber() { |
|
12 |
return numSolucGlobal; |
|
13 |
} |
|
14 |
|
|
15 |
public static void setGlobalSolutionNumber(int numSolucGlobal) { |
|
16 |
GlobalCounter.numSolucGlobal = numSolucGlobal; |
|
17 |
} |
|
18 |
|
|
19 |
/** |
|
20 |
* @return true if you need to initalize all nodes (every 65000 solutions only) |
|
21 |
* if true, do: |
|
22 |
* for (nodeNum = 0; nodeNum < graph.numVertices(); nodeNum++) { |
|
23 |
node = graph.getNodeByID(nodeNum); |
|
24 |
node.initialize(); |
|
25 |
} |
|
26 |
|
|
27 |
*/ |
|
28 |
public static boolean increment() { |
|
29 |
if (numSolucGlobal > 65000) { |
|
30 |
numSolucGlobal = -1; |
|
31 |
return true; |
|
32 |
} // for nodeNum */ |
|
33 |
numSolucGlobal++; |
|
34 |
return false; |
|
35 |
|
|
36 |
} |
|
37 |
|
|
38 |
} |
|
0 | 39 |
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/core/AbstractNetSolver.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
|
44 | 44 |
public class AbstractNetSolver implements INetSolver { |
45 |
public static int numSolucGlobal = 0; |
|
46 | 45 |
protected Network net; |
47 | 46 |
public Network getNetwork() { |
48 | 47 |
return net; |
... | ... | |
50 | 49 |
public void setNetwork(Network net) { |
51 | 50 |
this.net = net; |
52 | 51 |
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 | 52 |
|
57 | 53 |
} |
58 | 54 |
|
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/NetworkUtils.java | ||
---|---|---|
48 | 48 |
import com.iver.cit.gvsig.fmap.MapControl; |
49 | 49 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
50 | 50 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
51 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
|
51 | 52 |
import com.iver.cit.gvsig.fmap.core.symbols.PictureMarkerSymbol; |
52 | 53 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
53 | 54 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
... | ... | |
63 | 64 |
|
64 | 65 |
static private GeometryFactory geomFactory = new GeometryFactory(); |
65 | 66 |
|
67 |
private static IMarkerSymbol simFlag; |
|
68 |
|
|
66 | 69 |
public static void clearBarriersFromGraphics(MapControl mc) { |
67 | 70 |
GraphicLayer graphics = mc.getMapContext().getGraphicsLayer(); |
68 | 71 |
for (int i = graphics.getNumGraphics() - 1; i >= 0; i--) { |
... | ... | |
108 | 111 |
} |
109 | 112 |
|
110 | 113 |
public static void addGraphicFlag(MapControl mapControl, GvFlag flag) { |
111 |
GraphicLayer graphicLayer = mapControl.getMapContext() |
|
112 |
.getGraphicsLayer(); |
|
113 |
if (idSymbolFlag == -1) { |
|
114 |
PictureMarkerSymbol simFlag = new PictureMarkerSymbol(); |
|
114 |
addGraphicFlag(mapControl, flag, getDefaultSymbolFlag()); |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* @return |
|
119 |
*/ |
|
120 |
public static IMarkerSymbol getDefaultSymbolFlag() { |
|
121 |
if (simFlag == null) |
|
122 |
{ |
|
123 |
simFlag = new PictureMarkerSymbol(); |
|
115 | 124 |
simFlag.setSize(24); |
116 | 125 |
ImageIcon icon = new ImageIcon(NetworkUtils.class.getClassLoader() |
117 | 126 |
.getResource("images/pushpin.png")); |
118 |
simFlag.setImg(icon.getImage()); |
|
119 |
idSymbolFlag = graphicLayer.addSymbol(simFlag); |
|
127 |
((PictureMarkerSymbol)simFlag).setImg(icon.getImage()); |
|
120 | 128 |
} |
129 |
return simFlag; |
|
130 |
} |
|
131 |
public static void addGraphicFlag(MapControl mapControl, GvFlag flag, IMarkerSymbol sym) { |
|
132 |
GraphicLayer graphicLayer = mapControl.getMapContext() |
|
133 |
.getGraphicsLayer(); |
|
134 |
int idSymbol = graphicLayer.getSymbol(sym); |
|
135 |
if (idSymbol == -1) { // El s?mbolo no existe todav?a en la lista de gr?ficos |
|
136 |
idSymbol = graphicLayer.addSymbol(sym); |
|
137 |
} |
|
121 | 138 |
IGeometry gAux = ShapeFactory.createPoint2D(flag.getOriginalPoint() |
122 | 139 |
.getX(), flag.getOriginalPoint().getY()); |
123 |
FGraphic graphic = new FGraphic(gAux, idSymbolFlag);
|
|
140 |
FGraphic graphic = new FGraphic(gAux, idSymbol); |
|
124 | 141 |
graphic.setTag("FLAG"); |
125 | 142 |
graphic.setObjectTag(flag); |
126 | 143 |
graphicLayer.addGraphic(graphic); |
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/solvers/OneToManySolver.java | ||
---|---|---|
45 | 45 |
import sun.font.EAttribute; |
46 | 46 |
|
47 | 47 |
import com.iver.cit.gvsig.graph.core.AbstractNetSolver; |
48 |
import com.iver.cit.gvsig.graph.core.GlobalCounter; |
|
48 | 49 |
import com.iver.cit.gvsig.graph.core.GraphException; |
49 | 50 |
import com.iver.cit.gvsig.graph.core.GvEdge; |
50 | 51 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
... | ... | |
203 | 204 |
// Para evitar coincidencias cuando de la vuelta el contador, cada |
204 | 205 |
// 65000 peticiones (por ejemplo), repasamos toda |
205 | 206 |
// la red y ponemos numSolucGlobal a -1 |
206 |
if (numSolucGlobal > 65000) { |
|
207 |
numSolucGlobal = -1; |
|
208 |
|
|
207 |
if (GlobalCounter.increment()) |
|
208 |
{ |
|
209 | 209 |
for (nodeNum = 0; nodeNum < graph.numVertices(); nodeNum++) { |
210 | 210 |
node = graph.getNodeByID(nodeNum); |
211 | 211 |
node.initialize(); |
212 | 212 |
} // for nodeNum */ |
213 |
|
|
214 | 213 |
} |
215 |
numSolucGlobal++; |
|
216 | 214 |
|
217 | 215 |
candidatos.clear(); |
218 | 216 |
// A?adimos el Start Node a la lista de candidatosSTL |
... | ... | |
334 | 332 |
// Fin arco con coste negativo |
335 | 333 |
|
336 | 334 |
// NUEVO: 26-7-2003: Comprobamos si est? inicializado |
337 |
if (toNode.getNumSoluc() != numSolucGlobal) {
|
|
335 |
if (toNode.getNumSoluc() != GlobalCounter.getGlobalSolutionNumber()) {
|
|
338 | 336 |
toNode.initialize(); |
339 | 337 |
} |
340 | 338 |
else |
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/solvers/ServiceAreaExtractor.java | ||
---|---|---|
167 | 167 |
private SHPLayerDefinition layerDefPol; |
168 | 168 |
private Geometry serviceArea = null; |
169 | 169 |
private ArrayList <Geometry> serviceAreaPolygons; |
170 |
|
|
170 |
|
|
171 | 171 |
public ServiceAreaExtractor(Network net) throws BaseException { |
172 | 172 |
this.net = net; |
173 | 173 |
int aux = (int)(Math.random() * 1000); |
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/solvers/ShortestPathSolverAStar.java | ||
---|---|---|
53 | 53 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
54 | 54 |
import com.iver.cit.gvsig.graph.NetworkUtils; |
55 | 55 |
import com.iver.cit.gvsig.graph.core.AbstractNetSolver; |
56 |
import com.iver.cit.gvsig.graph.core.GlobalCounter; |
|
56 | 57 |
import com.iver.cit.gvsig.graph.core.GraphException; |
57 | 58 |
import com.iver.cit.gvsig.graph.core.GvEdge; |
58 | 59 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
... | ... | |
429 | 430 |
// Para evitar coincidencias cuando de la vuelta el contador, cada |
430 | 431 |
// 65000 peticiones (por ejemplo), repasamos toda |
431 | 432 |
// la red y ponemos numSolucGlobal a -1 |
432 |
if (numSolucGlobal > 65000) { |
|
433 |
numSolucGlobal = -1; |
|
434 |
|
|
433 |
if (GlobalCounter.increment()) |
|
434 |
{ |
|
435 | 435 |
for (nodeNum = 0; nodeNum < graph.numVertices(); nodeNum++) { |
436 | 436 |
node = graph.getNodeByID(nodeNum); |
437 | 437 |
node.initialize(); |
438 | 438 |
} // for nodeNum */ |
439 |
|
|
440 | 439 |
} |
441 |
numSolucGlobal++; |
|
442 | 440 |
|
443 | 441 |
candidatos.clear(); |
444 | 442 |
// A?adimos el Start Node a la lista de candidatosSTL |
... | ... | |
510 | 508 |
// Fin arco con coste negativo |
511 | 509 |
|
512 | 510 |
// NUEVO: 26-7-2003: Comprobamos si est? inicializado |
513 |
if (toNode.getNumSoluc() != numSolucGlobal) {
|
|
511 |
if (toNode.getNumSoluc() != GlobalCounter.getGlobalSolutionNumber()) {
|
|
514 | 512 |
toNode.initialize(); |
515 | 513 |
} else { |
516 | 514 |
// System.out.println("Nodo ya inicializado"); |
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/solvers/ShortestPathSolverDijkstra.java | ||
---|---|---|
51 | 51 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
52 | 52 |
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter; |
53 | 53 |
import com.iver.cit.gvsig.graph.core.AbstractNetSolver; |
54 |
import com.iver.cit.gvsig.graph.core.GlobalCounter; |
|
54 | 55 |
import com.iver.cit.gvsig.graph.core.GraphException; |
55 | 56 |
import com.iver.cit.gvsig.graph.core.GvEdge; |
56 | 57 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
... | ... | |
500 | 501 |
// Para evitar coincidencias cuando de la vuelta el contador, cada |
501 | 502 |
// 65000 peticiones (por ejemplo), repasamos toda |
502 | 503 |
// la red y ponemos numSolucGlobal a -1 |
503 |
if (numSolucGlobal > 65000) { |
|
504 |
numSolucGlobal = -1; |
|
505 |
|
|
504 |
if (GlobalCounter.increment()) |
|
505 |
{ |
|
506 | 506 |
for (nodeNum = 0; nodeNum < graph.numVertices(); nodeNum++) { |
507 | 507 |
node = graph.getNodeByID(nodeNum); |
508 | 508 |
node.initialize(); |
509 | 509 |
} // for nodeNum */ |
510 |
|
|
511 | 510 |
} |
512 |
numSolucGlobal++; |
|
513 | 511 |
|
514 | 512 |
candidatos.clear(); |
515 | 513 |
// A?adimos el Start Node a la lista de candidatosSTL |
... | ... | |
578 | 576 |
// Fin arco con coste negativo |
579 | 577 |
|
580 | 578 |
// NUEVO: 26-7-2003: Comprobamos si est? inicializado |
581 |
if (toNode.getNumSoluc() != numSolucGlobal) {
|
|
579 |
if (toNode.getNumSoluc() != GlobalCounter.getGlobalSolutionNumber()) {
|
|
582 | 580 |
toNode.initialize(); |
583 | 581 |
} |
584 | 582 |
else |
Also available in: Unified diff