Skip to content

Commit

Permalink
Находится массив dir
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-karpovich committed May 10, 2014
1 parent 142feda commit 8f454cc
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/main/java/Starter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void main(String[] args) {
"/*{3,4}*/\n" +
"/*{4,5}*/\n" +
"/*{5,3}*/\n" +
"/*{1,3}*/\n" +
"/*{3,1}*/\n" +

"/*widetilde{U}^3*/\n" +
"/*{2,3}*/\n" +
Expand Down Expand Up @@ -111,9 +111,9 @@ public static void main(String[] args) {

Structure system = Converter.convert(file);
system.calculate();
int flow=1;
for (int i=0; i<system.gettArray(flow).size(); i++){
System.out.print(system.gettArray(flow).get(i)+",");
int flow=0;
for (int i=0; i<system.getVertices(); i++){
System.out.print(system.getdArray(flow)[i]+",");
}
System.out.println("\nroot="+system.getRoot(flow));
System.out.println("OK");
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/by/bsu/coursework/structures/GraphWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ public static Integer[] getPArray(LinkedList<Edge> tree, LinkedList<Edge> newTre
LinkedList<Edge> tmpEdges2 = new LinkedList<>();
Stack<Integer> vertices = new Stack<>();

int edgesIdentifier=1;
edges=tmpEdges1;
tmpEdges=tmpEdges2;

for(Edge e:tree){
tmpEdges.add(e);
}
Expand Down Expand Up @@ -115,4 +113,26 @@ public static LinkedList<Integer> getTArray(LinkedList<Edge> tree, Integer[] pAr

return tmp;
}

public static Integer[] getDArray(LinkedList<Edge> flow, LinkedList<Edge> tree, int root, int size){
Integer[] d = new Integer[size];
for (int i=0; i<size; i++){
d[i]=-2;
}
d[root]=0;
for (Edge t:tree){
for (Edge f:flow){
if (t.getFrom()==f.getFrom() && t.getTo()==f.getTo()){
d[t.getFrom()]=1;
break;
}
else if (t.getFrom()==f.getTo() && t.getTo()==f.getFrom()){
d[t.getFrom()]=-1;
break;
}
}
}

return d;
}
}
11 changes: 10 additions & 1 deletion src/main/java/by/bsu/coursework/structures/Structure.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Structure {
private ArrayList<ArrayList<Integer>> alphas;
private ArrayList<LinkedList<Edge>> spanningTrees;
private ArrayList<Integer[]> pArrays;
private ArrayList<Integer[]> dArrays;
private ArrayList<LinkedList<Integer>> tArrays;
private ArrayList<Integer> roots;

Expand All @@ -39,6 +40,7 @@ public Structure(int types, int vertices) {
cyclicEdges = new ArrayList<>(types);
spanningTrees = new ArrayList<>(types);
pArrays = new ArrayList<>(types);
dArrays = new ArrayList<>(types);
tArrays = new ArrayList<>(types);
roots = new ArrayList<>(types);
for (int i=0; i<types; i++){
Expand All @@ -58,9 +60,12 @@ public void calculate() {
LinkedList<Edge> newTree = new LinkedList<>();
Integer[] pArray = GraphWorker.getPArray(tree, newTree, tree.get(0).getTo(), vertices);
LinkedList<Integer> tArray = GraphWorker.getTArray(newTree,pArray);
int root = tree.get(0).getTo();
Integer[] dArray = GraphWorker.getDArray(flow,newTree,root,vertices);
pArrays.add(pArray);
tArrays.add(tArray);
roots.add(tree.get(0).getTo());
dArrays.add(dArray);
roots.add(root);
}
}

Expand Down Expand Up @@ -109,6 +114,10 @@ public List<Integer> gettArrayInversed(int i) {
return tmp;
}

public Integer[] getdArray(int i) {
return dArrays.get(i);
}

public int getRoot(int i) {
return roots.get(i);
}
Expand Down

0 comments on commit 8f454cc

Please sign in to comment.