This repository was archived by the owner on Aug 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTempNetwork.java
More file actions
63 lines (54 loc) · 1.63 KB
/
TempNetwork.java
File metadata and controls
63 lines (54 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package net_simplex;
import java.util.ArrayList;
public class TempNetwork {
int nnodes, narcs;
ArrayList<Integer> demand;
ArrayList<Arc> arcarr;
public TempNetwork(int nnodes, int narcs) {
this.nnodes=nnodes;
this.narcs=narcs;
this.demand = new ArrayList<Integer>();
for(int i=0;i<nnodes;++i){
demand.add(0);
}
this.arcarr = new ArrayList<Arc>();
}
public void handleParallels() {
ArrayList< ArrayList<Integer>> nodeLists = new ArrayList< ArrayList< Integer >>();
for(int i=0;i<this.nnodes;++i){
nodeLists.add(new ArrayList<Integer>());
}
ArrayList<Integer> problemArcs=new ArrayList<Integer>();
for(int i=0;i<this.narcs;++i){
Arc temp=this.arcarr.get(i);
if(nodeLists.get(temp.startnode).contains(temp.endnode) || nodeLists.get(temp.endnode).contains(temp.startnode)){
problemArcs.add(i);
}
nodeLists.get(temp.startnode).add(temp.endnode);
}
int lengthen = problemArcs.size();
if(lengthen!=0){
System.out.println("This problem has parallel or antiparallel arcs");
}
this.nnodes+=lengthen;
this.narcs+=lengthen;
for(int i=0;i<lengthen;++i){
this.demand.add(0);
Arc temp = this.arcarr.get(problemArcs.get(i));
this.arcarr.add(new Arc(demand.size()-1,temp.endnode,temp.lowerb,temp.upperb,0,temp.flow,false));
temp.endnode=demand.size()-1;
}
}
public Network createNetwork() {
Network mincost = new Network(this.nnodes,this.narcs+this.nnodes-1);
for(int i=0;i<this.nnodes;++i){
if(this.demand.get(i)!=null){
mincost.demand[i]=this.demand.get(i);
}
}
for(int i=0;i<this.narcs;++i){
mincost.arcarr[i]=this.arcarr.get(i);
}
return mincost;
}
}