1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
package net.sourceforge.combean.test.graph.alg.spath; |
23 | |
|
24 | |
import junit.framework.TestCase; |
25 | |
import net.sourceforge.combean.graph.containers.MapAsEdgeMap; |
26 | |
import net.sourceforge.combean.interfaces.graph.Node; |
27 | |
import net.sourceforge.combean.interfaces.graph.alg.spath.SingleSourceShortestPathAlg; |
28 | |
import net.sourceforge.combean.interfaces.graph.containers.EdgeMap; |
29 | |
import net.sourceforge.combean.interfaces.graph.containers.FixedEdgeMap; |
30 | |
import net.sourceforge.combean.interfaces.graph.prop.ConstructableNumberedGraphProp; |
31 | |
import net.sourceforge.combean.interfaces.graph.prop.NeighborhoodGraphProp; |
32 | |
import net.sourceforge.combean.test.helpers.factories.GraphFixtureFactory; |
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
public abstract class AbstractGraphWithEdgeWeightsFixture |
39 | |
extends TestCase { |
40 | |
|
41 | 84 | protected Node startNode = null; |
42 | 84 | protected Node targetNode = null; |
43 | 84 | protected NeighborhoodGraphProp g = null; |
44 | 84 | protected FixedEdgeMap<Double> edgeWeights = null; |
45 | |
|
46 | 84 | protected ConstructableNumberedGraphProp constructG = null; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public AbstractGraphWithEdgeWeightsFixture( |
52 | |
int numNodes, int[][] edgesWithWeights) { |
53 | 84 | super(); |
54 | |
|
55 | 84 | constructGraph(numNodes, edgesWithWeights); |
56 | 84 | } |
57 | |
|
58 | |
private final void constructGraph(int numNodes, int[][] edgesWithWeights) { |
59 | 84 | EdgeMap<Double> tmpEdgeMap = new MapAsEdgeMap<Double>(); |
60 | 84 | this.constructG = |
61 | |
GraphFixtureFactory.createGraphWithEdgeWeights(numNodes, |
62 | |
edgesWithWeights, tmpEdgeMap); |
63 | 84 | this.edgeWeights = tmpEdgeMap; |
64 | |
|
65 | 84 | this.startNode = this.constructG.getNode(0); |
66 | 84 | this.targetNode = this.constructG.getNode(numNodes-1); |
67 | |
|
68 | 84 | this.g = (NeighborhoodGraphProp) this.constructG; |
69 | 84 | } |
70 | |
|
71 | |
protected final void runShortestPathAlg( |
72 | |
SingleSourceShortestPathAlg<Double> alg) { |
73 | 21 | alg.setGraph(this.g); |
74 | 21 | alg.setSource(this.startNode); |
75 | 21 | alg.setEdgeWeightMap(this.edgeWeights); |
76 | |
|
77 | 21 | alg.run(); |
78 | 21 | } |
79 | |
} |