root / trunk / extensions / extGraph / src-test / com / iver / cit / gvsig / graphtests / TestServiceArea2.java @ 15509
History | View | Annotate | Download (4.32 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
package com.iver.cit.gvsig.graphtests; |
43 |
|
44 |
import java.io.File; |
45 |
|
46 |
import junit.framework.TestCase; |
47 |
|
48 |
import org.cresques.cts.IProjection; |
49 |
import org.gvsig.exceptions.BaseException; |
50 |
|
51 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
52 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
53 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
54 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
55 |
import com.iver.cit.gvsig.graph.core.IGraph; |
56 |
import com.iver.cit.gvsig.graph.core.Network; |
57 |
import com.iver.cit.gvsig.graph.core.loaders.NetworkRedLoader; |
58 |
import com.iver.cit.gvsig.graph.solvers.OneToManySolver; |
59 |
import com.iver.cit.gvsig.graph.solvers.ServiceAreaExtractor2; |
60 |
|
61 |
public class TestServiceArea2 extends TestCase { |
62 |
|
63 |
FLyrVect lyr; |
64 |
Network net; |
65 |
IGraph g; |
66 |
|
67 |
|
68 |
protected void setUp() throws Exception { |
69 |
super.setUp();
|
70 |
// Setup de los drivers
|
71 |
LayerFactory |
72 |
.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
|
73 |
|
74 |
// Setup del factory de DataSources
|
75 |
|
76 |
IProjection prj = CRSFactory.getCRS("EPSG:23030");
|
77 |
File shpFile = new File("test_files/ejes.shp"); |
78 |
lyr = (FLyrVect) LayerFactory.createLayer("Ejes", "gvSIG shp driver", |
79 |
shpFile, prj); |
80 |
|
81 |
NetworkRedLoader netLoader = new NetworkRedLoader();
|
82 |
netLoader.setNetFile(new File("test_files/ejes.net")); |
83 |
g = netLoader.loadNetwork(); |
84 |
|
85 |
net = new Network();
|
86 |
} |
87 |
|
88 |
public void testCalculate() throws BaseException { |
89 |
OneToManySolver solver = new OneToManySolver();
|
90 |
net.setLayer(lyr); |
91 |
net.setGraph(g); |
92 |
solver.setNetwork(net); |
93 |
|
94 |
ServiceAreaExtractor2 extractor = new ServiceAreaExtractor2(net);
|
95 |
|
96 |
// Source flag
|
97 |
GvFlag sourceFlag = net.createFlag(441901, 4475977, 10); |
98 |
net.addFlag(sourceFlag); |
99 |
solver.setSourceFlag(sourceFlag); |
100 |
solver.addListener(extractor); |
101 |
|
102 |
// Destination flags
|
103 |
// NONE: We will use dijkstra algorithm to label network
|
104 |
// and extract (after) the visited arcs.
|
105 |
// net.addFlag(441901, 4475977, 10);
|
106 |
// net.addFlag(442830, 4476201, 200);
|
107 |
// net.addFlag(442673, 4475125, 200);
|
108 |
extractor.setIdFlag(0);
|
109 |
long t1 = System.currentTimeMillis(); |
110 |
solver.putDestinationsOnNetwork(); |
111 |
solver.setExploreAllNetwork(true);
|
112 |
solver.setMaxDistance(4000.0);
|
113 |
double[] costs = {1000.0, 2000.0}; |
114 |
extractor.setCosts(costs); |
115 |
|
116 |
solver.calculate(); |
117 |
|
118 |
|
119 |
// En este punto tenemos la red "etiquetada" con los pesos
|
120 |
// y distancias. Hay 2 opciones: recorrer toda la capa
|
121 |
// y copiar los registros que nos interesan (opci?n f?cil)
|
122 |
// o implementar un listener que vaya vigilando los
|
123 |
// arcos que se est?n evaluando dentro del algoritmo de
|
124 |
// dijkstra.
|
125 |
// Primero opci?n f?cil
|
126 |
// Recorremos la capa, vemos en qu? intervalo cae cada
|
127 |
// entidad y escribimos un shape.
|
128 |
extractor.closeFiles(); // 2000 en unidades de coste. Normalmente ser?n segundos
|
129 |
solver.removeDestinationsFromNetwork(); |
130 |
// TODO: Tambi?n puede ser interesante fijar un l?mite en distancia, no
|
131 |
// en tiempo
|
132 |
|
133 |
|
134 |
long t2 = System.currentTimeMillis(); |
135 |
System.out.println("tiempo:" + (t2-t1)); |
136 |
|
137 |
// assertEquals(dist.doubleValue(), 8887, 0);
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
} |
144 |
|
145 |
} |