Statistics
| Revision:

root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / graphtests / TestLoader.java @ 8028

History | View | Annotate | Download (6.44 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
package com.iver.cit.gvsig.graphtests;
42

    
43
import java.io.File;
44
import java.util.ArrayList;
45

    
46
import org.cresques.cts.IProjection;
47

    
48
import junit.framework.TestCase;
49

    
50
import com.hardcode.driverManager.Driver;
51
import com.hardcode.driverManager.DriverLoadException;
52
import com.hardcode.driverManager.DriverManager;
53
import com.hardcode.driverManager.DriverValidation;
54
import com.hardcode.gdbms.engine.data.DataSource;
55
import com.hardcode.gdbms.engine.data.DataSourceFactory;
56
import com.hardcode.gdbms.engine.data.NoSuchTableException;
57
import com.hardcode.gdbms.engine.data.driver.DBDriver;
58
import com.hardcode.gdbms.engine.data.driver.DriverException;
59
import com.hardcode.gdbms.engine.data.driver.FileDriver;
60
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
61
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
62
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
63
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
64
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
65
import com.iver.cit.gvsig.graph.GraphException;
66
import com.iver.cit.gvsig.graph.core.EdgeWeightLabeller;
67
import com.iver.cit.gvsig.graph.core.IGraph;
68
import com.iver.cit.gvsig.graph.core.NetworkLoader;
69
import com.iver.cit.gvsig.graph.core.NetworkRedLoader;
70
import com.iver.cit.gvsig.graph.solvers.Route;
71
import com.iver.cit.gvsig.graph.solvers.ShortestPathSolver;
72

    
73
import edu.uci.ics.jung.algorithms.shortestpath.DijkstraDistance;
74
import edu.uci.ics.jung.graph.ArchetypeVertex;
75
import edu.uci.ics.jung.graph.Graph;
76

    
77
public class TestLoader extends TestCase {
78
        DataSourceFactory dsf;
79
        FLyrVect lyr;
80
        
81
        
82
        public void testLoadRedNetwork() {
83
                NetworkRedLoader netLoader = new NetworkRedLoader();
84
                IGraph g = netLoader.loadNetwork();
85
                netLoader.loadJungNetwork();
86
                
87
                // Probamos la algoritmia: distancia entre nodo 1 y nodo 1000
88
                ShortestPathSolver solver = new ShortestPathSolver();
89
                solver.setLyrVect(lyr);
90
                solver.setGraph(g);
91
                
92
                // Primer punto
93
                solver.addFlag(443739.3, 4474704, 10);
94
                
95
                // Segundo punto
96
                solver.addFlag(443202.4, 4478132, 10);
97
                long t1 = System.currentTimeMillis();
98
                Route resul;
99
                try {
100
                        solver.setFielStreetName("Nombre");
101
                        resul = solver.calculateRoute();
102
                        long t2 = System.currentTimeMillis();
103
                        
104
//                        assertEquals(dist.doubleValue(), 8887, 0);
105
                        
106
                        System.out.println("dist =" + resul.getLength() + " meters. msecs: " + (t2-t1));
107
                        
108
                } catch (GraphException e) {
109
                        // TODO Auto-generated catch block
110
                        e.printStackTrace();
111
                }
112
                
113
        }
114
        
115
        /*
116
         * Test method for 'com.iver.cit.gvsig.graph.core.NetworkLoader.loadNetwork()'
117
         */
118
        public void testLoadNetwork() {
119
                NetworkLoader netLoader = new NetworkLoader();
120

    
121
        DataSource dsNodes;
122
                try {
123
                        dsNodes = dsf.createRandomDataSource("nodes",
124
                                DataSourceFactory.MANUAL_OPENING);
125
        
126
                DataSource dsEdges = dsf.createRandomDataSource("edges",
127
                        DataSourceFactory.MANUAL_OPENING);
128
                
129
                                
130
                        SelectableDataSource sdsNodes = new SelectableDataSource(dsNodes);
131
                        SelectableDataSource sdsEdges = new SelectableDataSource(dsEdges);
132
                        
133
                        netLoader.setNodeReader(sdsNodes);
134
                        netLoader.setEdgeReader(sdsEdges);
135
                        
136
                        
137
                        Graph g = netLoader.loadJungNetwork();
138
                        
139
                        System.out.println("Num nodos=" + g.numVertices() + " numEdges = " + g.numEdges());
140
                        
141
                        // Probamos la algoritmia: distancia entre nodo 1 y nodo 1000
142
                        DijkstraDistance distCalculator = new DijkstraDistance(g, new EdgeWeightLabeller());
143
                        ArchetypeVertex vOrig = netLoader.indexer.getVertex(1);
144
                        ArchetypeVertex vEnd = netLoader.indexer.getVertex(1000);
145
                        long t1 = System.currentTimeMillis();
146
                        Number dist = distCalculator.getDistance(vOrig, vEnd);
147
                        long t2 = System.currentTimeMillis();
148
                        
149
//                        assertEquals(dist.doubleValue(), 8887, 0);
150
                        
151
                        System.out.println("dist =" + dist + " meters. msecs: " + (t2-t1));
152
                        System.out.println(vOrig + " - " + vEnd);
153
                        System.out.println(vOrig.getUserDatum("X") + ", " + vOrig.getUserDatum("Y")
154
                                                        + " - " + vEnd.getUserDatum("X") + ", " + vEnd.getUserDatum("Y"));
155
                        
156
                } catch (DriverLoadException e) {
157
                        // TODO Auto-generated catch block
158
                        e.printStackTrace();
159
                } catch (NoSuchTableException e) {
160
                        // TODO Auto-generated catch block
161
                        e.printStackTrace();
162
                } catch (DriverException e) {
163
                        // TODO Auto-generated catch block
164
                        e.printStackTrace();
165
                }
166

    
167
        }
168

    
169
        protected void setUp() throws Exception {
170
                //Setup de los drivers
171
                DriverManager dm = new DriverManager();
172
                dm.setValidation(new DriverValidation() {
173
                                public boolean validate(Driver d) {
174
                                        return ((d instanceof ObjectDriver) ||
175
                                        (d instanceof FileDriver) ||
176
                                        (d instanceof DBDriver));
177
                                }
178
                        });
179
                dm.loadDrivers(new File("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers"));
180
                LayerFactory.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
181

    
182
                //Setup del factory de DataSources
183
        dsf = LayerFactory.getDataSourceFactory();
184
                dsf.setDriverManager(dm);
185

    
186
                //Setup de las tablas
187
                dsf.addFileDataSource("gdbms dbf driver", "nodes", "c:/nodes.dbf");
188
                dsf.addFileDataSource("gdbms dbf driver", "edges", "c:/edges.dbf");
189
                
190
                IProjection prj = CRSFactory.getCRS("EPSG:23030");
191
                File shpFile = new File("c:/ejes.shp");
192
                lyr = (FLyrVect) LayerFactory.createLayer("Ejes",
193
                                "gvSIG shp driver", shpFile, prj);
194
                
195

    
196
        }
197

    
198
        protected void tearDown() throws Exception {
199
                // TODO Auto-generated method stub
200
                super.tearDown();
201
        }
202

    
203
}
204

    
205