Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / graph / solvers / Route.java @ 8659

History | View | Annotate | Download (3.6 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.graph.solvers;
42

    
43
import java.util.ArrayList;
44

    
45
import com.hardcode.gdbms.engine.values.DoubleValue;
46
import com.hardcode.gdbms.engine.values.Value;
47
import com.hardcode.gdbms.engine.values.ValueFactory;
48
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
49
import com.iver.cit.gvsig.fmap.core.IFeature;
50
import com.iver.cit.gvsig.fmap.core.IGeometry;
51

    
52
/**
53
 * @author fjp
54
 * featureList es un array de IFeature.
55
 * Los campos que tiene cada feature son:
56
 * 0-> Id_Tramo (idArc sobre el que est? ese tramo de ruta.
57
 * 1-> Weight
58
 * 2-> Length
59
 * 3-> Texto calle o via por la que pasa.
60
 *
61
 */
62
public class Route {
63
        
64
        public static final int ID_ARC_INDEX = 0;
65
        public static final int WEIGHT_INDEX = 1;
66
        public static final int LENGTH_INDEX = 2;
67
        public static final int TEXT_INDEX = 3;
68
        
69
        
70
        
71
        
72
        
73
        
74
        
75
        public IFeature addRouteFeature(IGeometry geom, int idArc, double weight, double length, String text)
76
        {
77
                Value[] values = new Value[4];
78
                values[0] = ValueFactory.createValue(idArc);
79
                values[1] = ValueFactory.createValue(weight);
80
                values[2] = ValueFactory.createValue(length);
81
                values[3] = ValueFactory.createValue(text);
82
//                System.out.println("A?ado text= " + text);
83
                DefaultFeature feat = new DefaultFeature(geom, values, featureList.size() + "");
84
                featureList.add(feat);
85
                return feat;
86
        }
87
        private ArrayList featureList = new ArrayList();
88
        
89
        public ArrayList getFeatureList() 
90
        {
91
                return featureList;
92
        }
93
        
94
        public String getInstructions() {
95
                String instructions = "";
96
                double  distTotal = 0;
97
                for (int i=featureList.size()-1; i>=0; i--)
98
                {
99
                        IFeature feat = (IFeature) featureList.get(i);
100
                        DoubleValue length = (DoubleValue) feat.getAttribute(2);
101
                        double dist = length.doubleValue();
102
                        distTotal += dist;
103
                        instructions = instructions + "\n" + feat.getAttribute(3) + " dist=" + dist;
104
                }
105
                return instructions;
106
        }
107
        
108
        public double getLength() {
109
                double  distTotal = 0;
110
                for (int i=0; i < featureList.size(); i++)
111
                {
112
                        IFeature feat = (IFeature) featureList.get(i);
113
                        DoubleValue length = (DoubleValue) feat.getAttribute(2);
114
                        double dist = length.doubleValue();
115
                        distTotal += dist;
116
                }
117
                return distTotal;
118
        }
119
        
120
        public double getCost() {
121
                double  costTotal = 0;
122
                for (int i=0; i < featureList.size(); i++)
123
                {
124
                        IFeature feat = (IFeature) featureList.get(i);
125
                        DoubleValue costVal = (DoubleValue) feat.getAttribute(1);
126
                        double cost = costVal.doubleValue();
127
                        costTotal += cost;
128
                }
129
                return costTotal;                
130
        }
131
}
132

    
133