From 26c3ccb428c1604061f141e7e05dc3661a84718e Mon Sep 17 00:00:00 2001 From: Angel Cantu Date: Fri, 9 Feb 2018 18:34:53 -0600 Subject: [PATCH 1/5] testing --- src/main/java/com/asarg/polysim/models/base/ActiveGrid.java | 1 + src/main/java/com/asarg/polysim/models/base/Assembly.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/asarg/polysim/models/base/ActiveGrid.java b/src/main/java/com/asarg/polysim/models/base/ActiveGrid.java index 2399f2e..f000194 100644 --- a/src/main/java/com/asarg/polysim/models/base/ActiveGrid.java +++ b/src/main/java/com/asarg/polysim/models/base/ActiveGrid.java @@ -43,6 +43,7 @@ public void placePolytile(PolyTile p, int x, int y) { tmp = tmp.translate(x, y); this.put(tmp, t); } + } //If PolyTile p when translated by (x,y) matches the PolyTile at the destination, delete it from Grid diff --git a/src/main/java/com/asarg/polysim/models/base/Assembly.java b/src/main/java/com/asarg/polysim/models/base/Assembly.java index 964de43..98a488f 100644 --- a/src/main/java/com/asarg/polysim/models/base/Assembly.java +++ b/src/main/java/com/asarg/polysim/models/base/Assembly.java @@ -52,6 +52,7 @@ public class Assembly extends Observable { public Assembly() { tileSystem = new TileSystem(2, 0); frontier = new Frontier(tileSystem); + } public Assembly(TileSystem ts) { From 478ce9a7c4d9c3ddf211993873b42a87524a5c17 Mon Sep 17 00:00:00 2001 From: Angel Cantu Date: Fri, 9 Feb 2018 18:44:01 -0600 Subject: [PATCH 2/5] Testing: added Graph.java --- src/main/java/com/asarg/polysim/models/base/Assembly.java | 3 +++ src/main/java/com/asarg/polysim/models/base/Graph.java | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 src/main/java/com/asarg/polysim/models/base/Graph.java diff --git a/src/main/java/com/asarg/polysim/models/base/Assembly.java b/src/main/java/com/asarg/polysim/models/base/Assembly.java index 98a488f..a2a02be 100644 --- a/src/main/java/com/asarg/polysim/models/base/Assembly.java +++ b/src/main/java/com/asarg/polysim/models/base/Assembly.java @@ -68,6 +68,9 @@ public Assembly(TileSystem ts) { frontier = new Frontier(tileSystem); } + public void makeBondGraph(){ + Graph bondGraph = new Graph(); + } //change tile system stub public void changeTileSystem(TileSystem newTS) { System.out.println("WARNING: CHANGING THE TILE SYSTEM, PREPARE FOR ERRORS!"); diff --git a/src/main/java/com/asarg/polysim/models/base/Graph.java b/src/main/java/com/asarg/polysim/models/base/Graph.java new file mode 100644 index 0000000..a85491d --- /dev/null +++ b/src/main/java/com/asarg/polysim/models/base/Graph.java @@ -0,0 +1,7 @@ +package com.asarg.polysim.models.base; + +public class Graph { + public class Vertex{ + public String name; + } +} From c0a7a773c1a283604e5db7b609f0ff891ae4db76 Mon Sep 17 00:00:00 2001 From: AngelACantu Date: Wed, 21 Feb 2018 21:48:33 -0600 Subject: [PATCH 3/5] Added the North Trials: Find path north side --- bonder | 233 ++++++++++ final | 311 +++++++++++++ save | 93 ++++ .../asarg/polysim/models/base/Assembly.java | 37 ++ .../com/asarg/polysim/models/base/Graph.java | 433 +++++++++++++++++- test | 158 +++++++ tester | 163 +++++++ 7 files changed, 1427 insertions(+), 1 deletion(-) create mode 100644 bonder create mode 100644 final create mode 100644 save create mode 100644 test create mode 100644 tester diff --git a/bonder b/bonder new file mode 100644 index 0000000..24ac20e --- /dev/null +++ b/bonder @@ -0,0 +1,233 @@ + + + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + 2 + + + + + + e6e6e6 + o + + + -1.0 + -1 + + + + + e6e6e6 + n + q + + + -1.0 + -1 + + + + + e6e6e6 + p + q + + + -1.0 + -1 + + + + + e6e6e6 + h + m + p + i + + + -1.0 + -1 + + + + + e6e6e6 + l + n + m + + + -1.0 + -1 + + + + + e6e6e6 + k + o + l + g + + + -1.0 + -1 + + + + + e6e6e6 + k + j + + + -1.0 + -1 + + + + + e6e6e6 + j + h + + + -1.0 + -1 + + + + + e6e6e6 + d + i + + + -1.0 + -1 + + + + + e6e6e6 + h + g + f + e + + + -1.0 + -1 + + + + + e6e6e6 + e + d + c + + + -1.0 + -1 + + + + + e6e6e6 + c + b + + + -1.0 + -1 + + + + + e6e6e6 + b + a + + + -1.0 + -1 + + + + + e6e6e6 + a + + + -1.0 + -1 + + diff --git a/final b/final new file mode 100644 index 0000000..1a020b7 --- /dev/null +++ b/final @@ -0,0 +1,311 @@ + + + + + + 2 + + + + 1 + + + + 1 + + + + 2 + + + + 2 + + + + 1 + + + + 1 + + + + 1 + + + + 2 + + + + 2 + + + + 2 + + + + 1 + + + + 1 + + + + 1 + + + + 2 + + + + 1 + + + + 2 + + + + + + e6e6e6 + r + d0 + r + u0 + + + -1.0 + -1 + + + + + e6e6e6 + p + u3 + p + d0 + + + -1.0 + -1 + + + + + CCFFFF + g + u2 + g + u2 + + + -1.0 + -1 + + + + + B3E6E6 + g + u3 + g + u3 + + + -1.0 + -1 + + + + + E6804D + g + h3 + r + u3 + + + -1.0 + -1 + + + + + E6994D + g + u2 + p + h3 + + + -1.0 + -1 + + + + + CCE6FF + g + u0 + g + u0 + + + -1.0 + -1 + + + + + 99CCCC + g + u1 + g + u1 + + + -1.0 + -1 + + + + + E64D4D + g + h2 + r + u2 + + + -1.0 + -1 + + + + + E64D4D + g + u1 + p + h2 + + + -1.0 + -1 + + + + + 4D3399 + g + h1 + r + u1 + + + -1.0 + -1 + + + + + 4D3399 + g + u0 + p + h1 + + + -1.0 + -1 + + + + + FFFF66 + p + c3 + c0 + + + -1.0 + -1 + + + + + FFFF80 + g + c2 + c3 + + + -1.0 + -1 + + + + + FFFF99 + g + c1 + c2 + + + -1.0 + -1 + + + + + FFFFCC + r + c0 + c1 + + + -1.0 + -1 + + + + + 336633 + s2 + u0 + + + -1.0 + -1 + + + + + 336633 + s2 + s1 + u0 + + + -1.0 + -1 + + + + + 336633 + s1 + c1 + + + -1.0 + -1 + + diff --git a/save b/save new file mode 100644 index 0000000..63931ed --- /dev/null +++ b/save @@ -0,0 +1,93 @@ + + + + + + 2 + + + + 1 + + + + + + e6e6e6 + + + -1.0 + -1 + + + + + e6e6e6 + d + d + d + + + -1.0 + -1 + + + + + e6e6e6 + s1 + d + a1 + + + -1.0 + -1 + + + + + e6e6e6 + a1 + a1 + + + + -1.0 + -1 + + + + + e6e6e6 + a1 + + + + + e6e6e6 + d + d + + + + + e6e6e6 + d + + + + + e6e6e6 + d + + + + + e6e6e6 + d + + + -1.0 + -1 + + diff --git a/src/main/java/com/asarg/polysim/models/base/Assembly.java b/src/main/java/com/asarg/polysim/models/base/Assembly.java index a2a02be..679c6bf 100644 --- a/src/main/java/com/asarg/polysim/models/base/Assembly.java +++ b/src/main/java/com/asarg/polysim/models/base/Assembly.java @@ -69,7 +69,43 @@ public Assembly(TileSystem ts) { } public void makeBondGraph(){ + Set> tiles = Grid.entrySet(); Graph bondGraph = new Graph(); + + //get all vertices + for (Map.Entry mep : tiles) { + Coordinate pt = mep.getKey(); + Tile tile = mep.getValue(); + bondGraph.addVertex(tile.getLabel(), pt, tile.getGlueN(), + tile.getGlueS(), tile.getGlueW(), tile.getGlueE()); + } + for (Graph.Vertex v : bondGraph.vertices){ + for (Graph.Vertex vertex : bondGraph.vertices){ + if (v == vertex){ + + } + else{ + if (v.location.getEast().equals(vertex.location)){ + int strength = tileSystem.getStrength(v.E, vertex.W); + v.addEdge(vertex, strength, "E"); + } + else if (v.location.getWest().equals(vertex.location)){ + int strength = tileSystem.getStrength(v.W, vertex.E); + v.addEdge(vertex, strength, "W"); + } + else if (v.location.getNorth().equals(vertex.location)){ + int strength = tileSystem.getStrength(v.N, vertex.S); + v.addEdge(vertex, strength, "N"); + } + else if (v.location.getSouth().equals(vertex.location)){ + int strength = tileSystem.getStrength(v.S, vertex.N); + v.addEdge(vertex, strength, "S"); + } + } + } + } + bondGraph.printVertices(); + bondGraph.makeDualGraph(); } //change tile system stub public void changeTileSystem(TileSystem newTS) { @@ -88,6 +124,7 @@ public void changeTileSystem(TileSystem newTS) { public void changeTemperature(int temperature) { tileSystem.setTemperature(temperature); changeTileSystem(tileSystem); + makeBondGraph(); } public void changeTileConfiguration(TileConfiguration tc) { diff --git a/src/main/java/com/asarg/polysim/models/base/Graph.java b/src/main/java/com/asarg/polysim/models/base/Graph.java index a85491d..7fe65b8 100644 --- a/src/main/java/com/asarg/polysim/models/base/Graph.java +++ b/src/main/java/com/asarg/polysim/models/base/Graph.java @@ -1,7 +1,438 @@ package com.asarg.polysim.models.base; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class Graph { + public List vertices = new ArrayList<>(); + public List faceVertices = new ArrayList<>(); + public class Vertex{ - public String name; + public String tileLabel = new String();; + public List neighbors = new ArrayList<>(); + public Coordinate location; + public int mark = 0; + public int pathMark = 0; + public int edgeAmount = 0; + + + public Edge northNeighbor; + public Edge southNeighbor; + public Edge westNeighbor; + public Edge eastNeighbor; + + public String N; + public String W; + public String S; + public String E; + + public void addEdge(Vertex b, int strength, String where){ + neighbors.add(new Edge(b , strength, where)); + Edge e = new Edge(b, strength, where); + edgeAmount = edgeAmount + 1; + if (where == "N"){ + northNeighbor = e; + } + else if (where == "S"){ + southNeighbor = e; + } + else if (where == "W"){ + westNeighbor = e; + } + else if (where == "E"){ + eastNeighbor = e; + } + } + } + + public class Edge{ + public Vertex toVertex = new Vertex(); + public int bondStrength = 0; + public String direction = "X"; + + + public Edge(Vertex b, int strength, String where){ + toVertex = b; + bondStrength = strength; + direction = where; + } + } + public void printVertices(){ + for (Vertex v : vertices){ + System.out.print("Label: " + v.tileLabel); + System.out.print(" edgeAmount: " + v.edgeAmount); + System.out.print("-> "); + if (v.northNeighbor != null){ + System.out.print(v.northNeighbor.direction); + } + if(v.eastNeighbor != null){ + System.out.print(v.eastNeighbor.direction); + } + if (v.westNeighbor != null){ + System.out.print(v.westNeighbor.direction); + } + if (v.southNeighbor != null){ + System.out.print(v.southNeighbor.direction); + } + System.out.println("\n"); + } + } + + public void addVertex(String label, Coordinate pt, String N, String S, String W, String E){ + Vertex v = new Vertex(); + v.tileLabel = label; + v.location = pt; + v.N = N; + v.S = S; + v.W = W; + v.E = E; + vertices.add(v); + } + + public void makeDualGraph(){ + //mark all hairs + int amount = 0; + while(true){ + amount = markHairs(); + if (amount >= 2){ + break; + } + } + getFaces(); + } + + public void getFaces(){ + for (Vertex v : vertices){ + if (v.neighbors.size() == 1){ + System.out.print(" " + v.tileLabel + " A LONER TILE\n "); + } + else{ + for (Edge e : v.neighbors){ + if (e.direction.equals("N")){ + theNorthernTrials(v, e); + } + } + } + } + } + public int markHairs(){ + int minimum_edge_amount = 5; + for (Vertex v : vertices){ + if (v.edgeAmount == 1 && v.mark == 0){ + v.mark = 1; + for (Edge neighbor : v.neighbors){ + if (neighbor.toVertex.mark == 0){ + neighbor.toVertex.edgeAmount -= 1; + } + } + } + } + for (Vertex v : vertices){ + if (v.edgeAmount <= minimum_edge_amount && v.mark != 1){ + minimum_edge_amount = v.edgeAmount; + System.out.print(minimum_edge_amount); + } + System.out.print("} THIS: " + v.tileLabel + ", #" + v.edgeAmount + " {"); + } + + //print the mark ones + for (Vertex v : vertices){ + if (v.mark == 1){ + System.out.print("} THIS GUY IS MARKED: {" + v.tileLabel + "} "); + } + } + return minimum_edge_amount; + } + + + public void removePathMarkings(){ + for (Vertex v : vertices){ + v.pathMark = 0; + } + } + + + public void theNorthernTrials(Vertex v, Edge start){ + Vertex transv = new Vertex(); + Vertex endOfStack = v; + //north trial = 0 + //west trial = 1 + //south trial = 2 + //east trial = 3 + int trial = 0; + List northTrials_path = new ArrayList(); + List westTrials_path = new ArrayList(); + List southTrials_path = new ArrayList(); + List eastTrials_path = new ArrayList(); + + transv = start.toVertex; + String direction = "N"; + System.out.print("\nI am target tile: " + v.tileLabel + " and I'm at " + transv.tileLabel+ " "); + + + + //this is the north trial + //if both a west, east, and north, save east and north trial but go to the west trial + //if west trial fails, return to east or north, preferably north, saved and continue NORTH trial + int i = 0; + do { + System.out.print(" " + i + " "); + //check to see if multiple paths exist in the current vertex + //if all exist + + if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1 + && transv.northNeighbor.toVertex.pathMark != 1) { + System.out.print(" a "); + northTrials_path.add(transv.northNeighbor.toVertex); + northTrials_path.add(transv.eastNeighbor.toVertex); + transv = transv.westNeighbor.toVertex; + transv.pathMark = 1; + } + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.westNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.pathMark != 1 + && transv.northNeighbor.toVertex.pathMark != 1){ + System.out.print(" b "); + Vertex really = new Vertex(); + really = transv.northNeighbor.toVertex; + northTrials_path.add(really); + transv = transv.westNeighbor.toVertex; + transv.pathMark = 1; + } + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.northNeighbor.toVertex.pathMark != 1){ + System.out.print(" c "); + northTrials_path.add(transv.eastNeighbor.toVertex); + transv = transv.northNeighbor.toVertex; + transv.pathMark = 1; + } + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1){ + System.out.print(" c "); + northTrials_path.add(transv.eastNeighbor.toVertex); + transv = transv.westNeighbor.toVertex; + transv.pathMark = 1; + } + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.northNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.pathMark != 1){ + transv = transv.northNeighbor.toVertex; + transv.pathMark = 1; + } + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.westNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.pathMark != 1) { + System.out.print(" d "); + transv = transv.westNeighbor.toVertex; + transv.pathMark = 1; + } + else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1) { + System.out.print(" e "); + System.out.print("{Didn't move}"); + int count = 0; + if (!northTrials_path.isEmpty()){ + for (Vertex ok : northTrials_path){ + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1){ + transv = northTrials_path.get(0); + transv.pathMark = 1; + northTrials_path.remove(0); + } + } + } + + /* + if (!transv.eastNeighbor.direction.isEmpty() + && !transv.northNeighbor.direction.isEmpty() + && !transv.westNeighbor.direction.isEmpty() + + && transv.westNeighbor != null && transv.westNeighbor.direction != null + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && transv.westNeighbor.toVertex.mark != 1 && transv.westNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.mark != 1 && transv.eastNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 && transv.northNeighbor.toVertex.mark != 1 + ) { + System.out.print(" \na "); + System.out.print(transv.tileLabel + " "); + northTrials_path.add(transv.northNeighbor.toVertex); + northTrials_path.add(transv.eastNeighbor.toVertex); + transv = transv.westNeighbor.toVertex; + + } + //if N and W exist + else if (!transv.northNeighbor.direction.isEmpty() + && !transv.westNeighbor.direction.isEmpty() + + && transv.westNeighbor != null && transv.westNeighbor.direction != null + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && transv.northNeighbor.toVertex.mark != 1 && transv.westNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 && transv.westNeighbor.toVertex.mark != 1) { + System.out.print(" \nb "); + northTrials_path.add(transv.northNeighbor.toVertex); + System.out.print(transv.tileLabel + " "); + transv = transv.westNeighbor.toVertex; + } + //if N and E exist + else if (!transv.northNeighbor.direction.isEmpty() + && !transv.eastNeighbor.direction.isEmpty() + + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && transv.eastNeighbor.toVertex.mark != 1 && transv.eastNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 && transv.northNeighbor.toVertex.mark != 1 ) { + System.out.print(" \nc "); + System.out.print(transv.tileLabel + " "); + northTrials_path.add(transv.northNeighbor.toVertex); + transv = transv.eastNeighbor.toVertex; + //if N and E exist + + } + else if (!transv.eastNeighbor.direction.isEmpty() + && !transv.northNeighbor.direction.isEmpty() + && !transv.westNeighbor.direction.isEmpty() + + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && transv.northNeighbor.toVertex.mark != 1 + && transv.westNeighbor == null && transv.westNeighbor.direction == null + && transv.eastNeighbor == null && transv.eastNeighbor.direction == null){ + System.out.print("NORTH ONLI"); + } + else if (!transv.eastNeighbor.direction.isEmpty() + && !transv.northNeighbor.direction.isEmpty() + && !transv.westNeighbor.direction.isEmpty() + + && transv.westNeighbor != null && transv.westNeighbor.direction != null + && transv.westNeighbor.toVertex.mark != 1 + && transv.northNeighbor == null && transv.northNeighbor.direction == null + && transv.eastNeighbor == null && transv.eastNeighbor.direction == null) { + System.out.print(" \nd "); + System.out.print(transv.tileLabel + " "); + System.out.print("TIME TO WEST TRIALZ"); + } + else{ + System.out.print(" \ne "); + System.out.print(transv.tileLabel + " "); + if (!northTrials_path.isEmpty()){ + transv = northTrials_path.get(0); + northTrials_path.remove(0); + } + } + System.out.print(" \ni "); + //IF ONLY WEST DIRECTION EXIST, GO TO WEST TRIALZ + i++; + if (i > 10){ + System.out.print("END "); + break; + } + */ + System.out.print("{" + transv.tileLabel + "}, "); + i++; + if (i > 20){ + System.out.print(" END "); + removePathMarkings(); + break; + } + }while(!transv.equals(v)); + + + + + + + /* + do{ + if (transv.westNeighbor != null && transv.westNeighbor.direction != null && !transv.westNeighbor.direction.isEmpty() + && transv.westNeighbor.direction.equals("W") && direction.equals("N") && transv.westNeighbor.toVertex.mark != 1){ + direction = "W"; + System.out.print(" Go West "); + transv = transv.westNeighbor.toVertex; + System.out.print(transv.tileLabel + " "); + } + else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && !transv.southNeighbor.direction.isEmpty() + && transv.southNeighbor.direction.equals("S") && direction.equals("W") && transv.southNeighbor.toVertex.mark != 1){ + direction = "S"; + System.out.print(" Go South "); + transv = transv.southNeighbor.toVertex; + System.out.print(transv.tileLabel + " "); + } + else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.direction.equals("E") && direction.equals("S") && transv.eastNeighbor.toVertex.mark != 1){ + direction = "E"; + System.out.print(" Go East "); + transv = transv.eastNeighbor.toVertex; + System.out.print(transv.tileLabel + " "); + } + //this next half moves it forward more-> + else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.direction.equals("E") && direction.equals("E") && transv.eastNeighbor.toVertex.mark != 1){ + direction = "E"; + System.out.print(" Go East "); + transv = transv.eastNeighbor.toVertex; + System.out.print(transv.tileLabel + " "); + } + else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && !transv.southNeighbor.direction.isEmpty() + && transv.southNeighbor.direction.equals("S") && direction.equals("S") && transv.southNeighbor.toVertex.mark != 1){ + direction = "S"; + System.out.print(" Go South "); + transv = transv.southNeighbor.toVertex; + System.out.print(transv.tileLabel + " "); + } + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && !transv.westNeighbor.direction.isEmpty() + && transv.westNeighbor.direction.equals("W") && direction.equals("W") && transv.westNeighbor.toVertex.mark != 1){ + direction = "W"; + System.out.print(" Go West "); + transv = transv.westNeighbor.toVertex; + System.out.print(transv.tileLabel + " "); + } + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null && !transv.northNeighbor.direction.isEmpty() + && transv.northNeighbor.direction.equals("W") && direction.equals("W") && transv.northNeighbor.toVertex.mark != 1){ + direction = "W"; + System.out.print(" Go North "); + transv = transv.northNeighbor.toVertex; + System.out.print(transv.tileLabel + " "); + } + else{ + System.out.print(" Landed on: " + transv.tileLabel); + return; + } + }while(!transv.equals(v)); + */ } } diff --git a/test b/test new file mode 100644 index 0000000..91e661f --- /dev/null +++ b/test @@ -0,0 +1,158 @@ + + + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + -1.0 + -1 + + diff --git a/tester b/tester new file mode 100644 index 0000000..71311f6 --- /dev/null +++ b/tester @@ -0,0 +1,163 @@ + + + + + + 1 + + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + + + e6e6e6 + + + -1.0 + -1 + + From d259369315687f3a3fe33600295d030f1f83f2ac Mon Sep 17 00:00:00 2001 From: AngelACantu Date: Thu, 22 Feb 2018 01:43:45 -0600 Subject: [PATCH 4/5] Finding faces --- .../com/asarg/polysim/models/base/Graph.java | 941 ++++++++++++------ 1 file changed, 652 insertions(+), 289 deletions(-) diff --git a/src/main/java/com/asarg/polysim/models/base/Graph.java b/src/main/java/com/asarg/polysim/models/base/Graph.java index 7fe65b8..264ce65 100644 --- a/src/main/java/com/asarg/polysim/models/base/Graph.java +++ b/src/main/java/com/asarg/polysim/models/base/Graph.java @@ -8,8 +8,9 @@ public class Graph { public List vertices = new ArrayList<>(); public List faceVertices = new ArrayList<>(); - public class Vertex{ - public String tileLabel = new String();; + public class Vertex { + public String tileLabel = new String(); + ; public List neighbors = new ArrayList<>(); public Coordinate location; public int mark = 0; @@ -27,59 +28,57 @@ public class Vertex{ public String S; public String E; - public void addEdge(Vertex b, int strength, String where){ - neighbors.add(new Edge(b , strength, where)); + public void addEdge(Vertex b, int strength, String where) { + neighbors.add(new Edge(b, strength, where)); Edge e = new Edge(b, strength, where); edgeAmount = edgeAmount + 1; - if (where == "N"){ + if (where == "N") { northNeighbor = e; - } - else if (where == "S"){ + } else if (where == "S") { southNeighbor = e; - } - else if (where == "W"){ + } else if (where == "W") { westNeighbor = e; - } - else if (where == "E"){ + } else if (where == "E") { eastNeighbor = e; } } } - public class Edge{ + public class Edge { public Vertex toVertex = new Vertex(); public int bondStrength = 0; public String direction = "X"; - public Edge(Vertex b, int strength, String where){ + public Edge(Vertex b, int strength, String where) { toVertex = b; bondStrength = strength; direction = where; } } - public void printVertices(){ - for (Vertex v : vertices){ + + public void printVertices() { + for (Vertex v : vertices) { System.out.print("Label: " + v.tileLabel); System.out.print(" edgeAmount: " + v.edgeAmount); System.out.print("-> "); - if (v.northNeighbor != null){ + if (v.northNeighbor != null) { System.out.print(v.northNeighbor.direction); } - if(v.eastNeighbor != null){ + if (v.eastNeighbor != null) { System.out.print(v.eastNeighbor.direction); } - if (v.westNeighbor != null){ + if (v.westNeighbor != null) { System.out.print(v.westNeighbor.direction); } - if (v.southNeighbor != null){ + if (v.southNeighbor != null) { System.out.print(v.southNeighbor.direction); } System.out.println("\n"); } } - public void addVertex(String label, Coordinate pt, String N, String S, String W, String E){ + public void addVertex(String label, Coordinate pt, String N, String S, String W, String E) { Vertex v = new Vertex(); v.tileLabel = label; v.location = pt; @@ -90,46 +89,46 @@ public void addVertex(String label, Coordinate pt, String N, String S, String W, vertices.add(v); } - public void makeDualGraph(){ + public void makeDualGraph() { //mark all hairs int amount = 0; - while(true){ + while (true) { amount = markHairs(); - if (amount >= 2){ + if (amount >= 2) { break; } } getFaces(); } - public void getFaces(){ - for (Vertex v : vertices){ - if (v.neighbors.size() == 1){ + public void getFaces() { + for (Vertex v : vertices) { + if (v.neighbors.size() == 1) { System.out.print(" " + v.tileLabel + " A LONER TILE\n "); - } - else{ - for (Edge e : v.neighbors){ - if (e.direction.equals("N")){ - theNorthernTrials(v, e); + } else { + for (Edge e : v.neighbors) { + if (e.direction.equals("N")) { + theTrials(v, e); } } } } } - public int markHairs(){ + + public int markHairs() { int minimum_edge_amount = 5; - for (Vertex v : vertices){ - if (v.edgeAmount == 1 && v.mark == 0){ + for (Vertex v : vertices) { + if (v.edgeAmount == 1 && v.mark == 0) { v.mark = 1; - for (Edge neighbor : v.neighbors){ - if (neighbor.toVertex.mark == 0){ + for (Edge neighbor : v.neighbors) { + if (neighbor.toVertex.mark == 0) { neighbor.toVertex.edgeAmount -= 1; } } } } - for (Vertex v : vertices){ - if (v.edgeAmount <= minimum_edge_amount && v.mark != 1){ + for (Vertex v : vertices) { + if (v.edgeAmount <= minimum_edge_amount && v.mark != 1) { minimum_edge_amount = v.edgeAmount; System.out.print(minimum_edge_amount); } @@ -137,8 +136,8 @@ public int markHairs(){ } //print the mark ones - for (Vertex v : vertices){ - if (v.mark == 1){ + for (Vertex v : vertices) { + if (v.mark == 1) { System.out.print("} THIS GUY IS MARKED: {" + v.tileLabel + "} "); } } @@ -146,20 +145,21 @@ public int markHairs(){ } - public void removePathMarkings(){ - for (Vertex v : vertices){ + public void removePathMarkings() { + for (Vertex v : vertices) { v.pathMark = 0; } } - public void theNorthernTrials(Vertex v, Edge start){ + public void theTrials(Vertex v, Edge start) { Vertex transv = new Vertex(); - Vertex endOfStack = v; + Vertex notTransv = new Vertex(); //north trial = 0 //west trial = 1 //south trial = 2 //east trial = 3 + int flag = 0; int trial = 0; List northTrials_path = new ArrayList(); List westTrials_path = new ArrayList(); @@ -167,9 +167,9 @@ public void theNorthernTrials(Vertex v, Edge start){ List eastTrials_path = new ArrayList(); transv = start.toVertex; + notTransv = v; String direction = "N"; - System.out.print("\nI am target tile: " + v.tileLabel + " and I'm at " + transv.tileLabel+ " "); - + System.out.print("\nI am target tile: " + v.tileLabel + " and I'm at " + transv.tileLabel + " "); //this is the north trial @@ -178,261 +178,624 @@ public void theNorthernTrials(Vertex v, Edge start){ int i = 0; do { System.out.print(" " + i + " "); - //check to see if multiple paths exist in the current vertex - //if all exist - - if (transv.northNeighbor != null && transv.northNeighbor.direction != null - && !transv.northNeighbor.direction.isEmpty() - && transv.westNeighbor != null && transv.westNeighbor.direction != null - && !transv.westNeighbor.direction.isEmpty() - && transv.eastNeighbor != null && transv.eastNeighbor.direction != null - && !transv.eastNeighbor.direction.isEmpty() - && transv.eastNeighbor.toVertex.mark != 1 - && transv.westNeighbor.toVertex.mark != 1 - && transv.northNeighbor.toVertex.mark != 1 - && transv.eastNeighbor.toVertex.pathMark != 1 - && transv.westNeighbor.toVertex.pathMark != 1 - && transv.northNeighbor.toVertex.pathMark != 1) { - System.out.print(" a "); - northTrials_path.add(transv.northNeighbor.toVertex); - northTrials_path.add(transv.eastNeighbor.toVertex); - transv = transv.westNeighbor.toVertex; - transv.pathMark = 1; - } - else if (transv.northNeighbor != null && transv.northNeighbor.direction != null - && !transv.northNeighbor.direction.isEmpty() - && transv.westNeighbor != null && transv.westNeighbor.direction != null - && !transv.westNeighbor.direction.isEmpty() - && transv.westNeighbor.toVertex.mark != 1 - && transv.northNeighbor.toVertex.mark != 1 - && transv.westNeighbor.toVertex.pathMark != 1 - && transv.northNeighbor.toVertex.pathMark != 1){ - System.out.print(" b "); - Vertex really = new Vertex(); - really = transv.northNeighbor.toVertex; - northTrials_path.add(really); - transv = transv.westNeighbor.toVertex; - transv.pathMark = 1; - } - else if (transv.northNeighbor != null && transv.northNeighbor.direction != null - && !transv.northNeighbor.direction.isEmpty() - && transv.eastNeighbor != null && transv.eastNeighbor.direction != null - && !transv.eastNeighbor.direction.isEmpty() - && transv.eastNeighbor.toVertex.mark != 1 - && transv.northNeighbor.toVertex.mark != 1 - && transv.eastNeighbor.toVertex.pathMark != 1 - && transv.northNeighbor.toVertex.pathMark != 1){ - System.out.print(" c "); - northTrials_path.add(transv.eastNeighbor.toVertex); - transv = transv.northNeighbor.toVertex; - transv.pathMark = 1; - } - else if (transv.westNeighbor != null && transv.westNeighbor.direction != null - && !transv.westNeighbor.direction.isEmpty() - && transv.eastNeighbor != null && transv.eastNeighbor.direction != null - && !transv.eastNeighbor.direction.isEmpty() - && transv.southNeighbor != null && transv.southNeighbor.direction != null - && !transv.southNeighbor.direction.isEmpty() - && transv.eastNeighbor.toVertex.mark != 1 - && transv.westNeighbor.toVertex.mark != 1 - && transv.southNeighbor.toVertex.mark != 1 - && transv.eastNeighbor.toVertex.pathMark != 1 - && transv.westNeighbor.toVertex.pathMark != 1){ - System.out.print(" c "); - northTrials_path.add(transv.eastNeighbor.toVertex); - transv = transv.westNeighbor.toVertex; - transv.pathMark = 1; - } - else if (transv.northNeighbor != null && transv.northNeighbor.direction != null - && !transv.northNeighbor.direction.isEmpty() - && transv.northNeighbor.toVertex.mark != 1 - && transv.northNeighbor.toVertex.pathMark != 1){ - transv = transv.northNeighbor.toVertex; - transv.pathMark = 1; - } - else if (transv.westNeighbor != null && transv.westNeighbor.direction != null - && !transv.westNeighbor.direction.isEmpty() - && transv.westNeighbor.toVertex.mark != 1 - && transv.westNeighbor.toVertex.pathMark != 1) { - System.out.print(" d "); - transv = transv.westNeighbor.toVertex; - transv.pathMark = 1; - } - else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null - && !transv.eastNeighbor.direction.isEmpty() - && transv.eastNeighbor.toVertex.mark != 1) { - System.out.print(" e "); - System.out.print("{Didn't move}"); - int count = 0; - if (!northTrials_path.isEmpty()){ - for (Vertex ok : northTrials_path){ - System.out.print(ok.tileLabel + " "); - count = count + 1; + //////////////////////////////////////////////////////////// + //THE NORTH TRIALS////////////////////////////////////////// + if (trial == 0) { + System.out.print("North Trials\n"); + //////////////////////////////////////////////////////////// + ////////////////// + // | + // -o- + //////////////////////////////////////////////////////////// + if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + + && transv.eastNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1 + && transv.northNeighbor.toVertex.pathMark != 1) { + northTrials_path.add(transv.northNeighbor.toVertex); + northTrials_path.add(transv.eastNeighbor.toVertex); + transv = transv.westNeighbor.toVertex; + trial = 1; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // -o + //////////////////////////////////////////////////////////// + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.westNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.pathMark != 1 + && transv.northNeighbor.toVertex.pathMark != 1) { + northTrials_path.add(transv.northNeighbor.toVertex); + transv = transv.westNeighbor.toVertex; + trial = 1; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // o- + //////////////////////////////////////////////////////////// + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.northNeighbor.toVertex.pathMark != 1) { + northTrials_path.add(transv.eastNeighbor.toVertex); + transv = transv.northNeighbor.toVertex; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // -o- + // | + //////////////////////////////////////////////////////////// + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1) { + northTrials_path.add(transv.eastNeighbor.toVertex); + transv = transv.westNeighbor.toVertex; + trial = 1; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // o + //////////////////////////////////////////////////////////// + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.northNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.pathMark != 1) { + transv = transv.northNeighbor.toVertex; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // -o + // + //////////////////////////////////////////////////////////// + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.westNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.pathMark != 1) { + transv = transv.westNeighbor.toVertex; + transv.pathMark = 1; + trial = 1; + } + //////////////////////////////////////////////////////////// + // o- + // + //////////////////////////////////////////////////////////// + else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1 + && transv.pathMark != 1) { + int count = 0; + if (!northTrials_path.isEmpty()) { + for (Vertex ok : northTrials_path) { + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + transv = northTrials_path.get(0); + transv.pathMark = 1; + northTrials_path.remove(0); + } else { + notTransv = transv; + } } - if (count >= 1){ - transv = northTrials_path.get(0); - transv.pathMark = 1; - northTrials_path.remove(0); + } + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + } else if (trial == 1) { + System.out.print("West Trials\n"); + //////////////////////////////////////////////////////////// + //THE WEST TRIALS////////////////////////////////////////// + //////////////////////////////////////////////////////////// + ////////////////// + // + // + //////////////////////////////////////////////////////////// + if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + + && transv.southNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + + && transv.southNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1 + && transv.northNeighbor.toVertex.pathMark != 1) { + westTrials_path.add(transv.westNeighbor.toVertex); + westTrials_path.add(transv.northNeighbor.toVertex); + transv = transv.southNeighbor.toVertex; + trial = 2; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // -o + //////////////////////////////////////////////////////////// + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + + && transv.southNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 + + && transv.southNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1) { + westTrials_path.add(transv.westNeighbor.toVertex); + transv = transv.southNeighbor.toVertex; + trial = 2; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // o- + //////////////////////////////////////////////////////////// + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.northNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1) { + westTrials_path.add(transv.northNeighbor.toVertex); + transv = transv.westNeighbor.toVertex; + + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // -o- + // | + //////////////////////////////////////////////////////////// + else if (transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + + && transv.southNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + + && transv.northNeighbor.toVertex.pathMark != 1 + && transv.southNeighbor.toVertex.pathMark != 1) { + westTrials_path.add(transv.northNeighbor.toVertex); + transv = transv.southNeighbor.toVertex; + trial = 2; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // o + //////////////////////////////////////////////////////////// + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.westNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.pathMark != 1) { + transv = transv.westNeighbor.toVertex; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // -o + // + //////////////////////////////////////////////////////////// + else if (transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.southNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.pathMark != 1) { + transv = transv.southNeighbor.toVertex; + transv.pathMark = 1; + trial = 2; + } + //////////////////////////////////////////////////////////// + // o- + // + //////////////////////////////////////////////////////////// + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.northNeighbor.toVertex.mark != 1 + && transv.pathMark != 1) { + int count = 0; + if (!westTrials_path.isEmpty()) { + for (Vertex ok : westTrials_path) { + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + transv = westTrials_path.get(0); + transv.pathMark = 1; + westTrials_path.remove(0); + } else { + notTransv = transv; + } } } - } - - /* - if (!transv.eastNeighbor.direction.isEmpty() - && !transv.northNeighbor.direction.isEmpty() - && !transv.westNeighbor.direction.isEmpty() - - && transv.westNeighbor != null && transv.westNeighbor.direction != null - && transv.eastNeighbor != null && transv.eastNeighbor.direction != null - && transv.northNeighbor != null && transv.northNeighbor.direction != null - && transv.westNeighbor.toVertex.mark != 1 && transv.westNeighbor.toVertex.mark != 1 - && transv.eastNeighbor.toVertex.mark != 1 && transv.eastNeighbor.toVertex.mark != 1 - && transv.northNeighbor.toVertex.mark != 1 && transv.northNeighbor.toVertex.mark != 1 - ) { - System.out.print(" \na "); - System.out.print(transv.tileLabel + " "); - northTrials_path.add(transv.northNeighbor.toVertex); - northTrials_path.add(transv.eastNeighbor.toVertex); - transv = transv.westNeighbor.toVertex; - - } - //if N and W exist - else if (!transv.northNeighbor.direction.isEmpty() - && !transv.westNeighbor.direction.isEmpty() - - && transv.westNeighbor != null && transv.westNeighbor.direction != null - && transv.northNeighbor != null && transv.northNeighbor.direction != null - && transv.northNeighbor.toVertex.mark != 1 && transv.westNeighbor.toVertex.mark != 1 - && transv.westNeighbor.toVertex.mark != 1 && transv.westNeighbor.toVertex.mark != 1) { - System.out.print(" \nb "); - northTrials_path.add(transv.northNeighbor.toVertex); - System.out.print(transv.tileLabel + " "); - transv = transv.westNeighbor.toVertex; - } - //if N and E exist - else if (!transv.northNeighbor.direction.isEmpty() - && !transv.eastNeighbor.direction.isEmpty() - - && transv.eastNeighbor != null && transv.eastNeighbor.direction != null - && transv.northNeighbor != null && transv.northNeighbor.direction != null - && transv.eastNeighbor.toVertex.mark != 1 && transv.eastNeighbor.toVertex.mark != 1 - && transv.northNeighbor.toVertex.mark != 1 && transv.northNeighbor.toVertex.mark != 1 ) { - System.out.print(" \nc "); - System.out.print(transv.tileLabel + " "); - northTrials_path.add(transv.northNeighbor.toVertex); - transv = transv.eastNeighbor.toVertex; - //if N and E exist - - } - else if (!transv.eastNeighbor.direction.isEmpty() - && !transv.northNeighbor.direction.isEmpty() - && !transv.westNeighbor.direction.isEmpty() - - && transv.northNeighbor != null && transv.northNeighbor.direction != null - && transv.northNeighbor.toVertex.mark != 1 - && transv.westNeighbor == null && transv.westNeighbor.direction == null - && transv.eastNeighbor == null && transv.eastNeighbor.direction == null){ - System.out.print("NORTH ONLI"); - } - else if (!transv.eastNeighbor.direction.isEmpty() - && !transv.northNeighbor.direction.isEmpty() - && !transv.westNeighbor.direction.isEmpty() - - && transv.westNeighbor != null && transv.westNeighbor.direction != null - && transv.westNeighbor.toVertex.mark != 1 - && transv.northNeighbor == null && transv.northNeighbor.direction == null - && transv.eastNeighbor == null && transv.eastNeighbor.direction == null) { - System.out.print(" \nd "); - System.out.print(transv.tileLabel + " "); - System.out.print("TIME TO WEST TRIALZ"); - } - else{ - System.out.print(" \ne "); - System.out.print(transv.tileLabel + " "); - if (!northTrials_path.isEmpty()){ - transv = northTrials_path.get(0); - northTrials_path.remove(0); + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + } else if (trial == 2) { + System.out.print("South Trials\n"); + //////////////////////////////////////////////////////////// + //THE SOUTH TRIALS////////////////////////////////////////// + //////////////////////////////////////////////////////////// + ////////////////// + // + // + //////////////////////////////////////////////////////////// + if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + + && transv.eastNeighbor.toVertex.mark != 1 + && transv.westNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.mark != 1 + + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1 + && transv.southNeighbor.toVertex.pathMark != 1) { + southTrials_path.add(transv.westNeighbor.toVertex); + southTrials_path.add(transv.southNeighbor.toVertex); + transv = transv.eastNeighbor.toVertex; + trial = 3; + transv.pathMark = 1; } + //////////////////////////////////////////////////////////// + // | + // -o + //////////////////////////////////////////////////////////// + else if (transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + + && transv.eastNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.mark != 1 + + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.southNeighbor.toVertex.pathMark != 1) { + southTrials_path.add(transv.southNeighbor.toVertex); + transv = transv.eastNeighbor.toVertex; + trial = 3; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // o- + //////////////////////////////////////////////////////////// + else if (transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + + && transv.northNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.mark != 1 + + && transv.northNeighbor.toVertex.pathMark != 1 + && transv.southNeighbor.toVertex.pathMark != 1) { + southTrials_path.add(transv.northNeighbor.toVertex); + transv = transv.southNeighbor.toVertex; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // -o- + // | + //////////////////////////////////////////////////////////// + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + + && transv.westNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.mark != 1 + + && transv.eastNeighbor.toVertex.pathMark != 1 + && transv.westNeighbor.toVertex.pathMark != 1) { + southTrials_path.add(transv.westNeighbor.toVertex); + transv = transv.eastNeighbor.toVertex; + trial = 3; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // o + //////////////////////////////////////////////////////////// + else if (transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.southNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.pathMark != 1) { + transv = transv.southNeighbor.toVertex; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // -o + // + //////////////////////////////////////////////////////////// + else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1) { + transv = transv.eastNeighbor.toVertex; + trial = 3; + transv.pathMark = 1; + trial = 3; + } + //////////////////////////////////////////////////////////// + // o- + // + //////////////////////////////////////////////////////////// + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.westNeighbor.toVertex.mark != 1 + && transv.pathMark != 1) { + int count = 0; + if (!southTrials_path.isEmpty()) { + for (Vertex ok : southTrials_path) { + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + transv = southTrials_path.get(0); + transv.pathMark = 1; + southTrials_path.remove(0); + } else { + notTransv = transv; + } + } + } + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + } else if (trial == 3) { + System.out.print("East Trials\n"); + //////////////////////////////////////////////////////////// + //THE EAST TRIALS////////////////////////////////////////// + //////////////////////////////////////////////////////////// + ////////////////// + // | + // -o- + //////////////////////////////////////////////////////////// + if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + + && transv.northNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.mark != 1 + + && transv.northNeighbor.toVertex.pathMark != 1 + && transv.southNeighbor.toVertex.pathMark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1) { + eastTrials_path.add(transv.eastNeighbor.toVertex); + eastTrials_path.add(transv.southNeighbor.toVertex); + transv = transv.northNeighbor.toVertex; + trial = 0; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // -o + //////////////////////////////////////////////////////////// + else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + + && transv.northNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.mark != 1 + + && transv.northNeighbor.toVertex.pathMark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1) { + eastTrials_path.add(transv.eastNeighbor.toVertex); + transv = transv.northNeighbor.toVertex; + trial = 0; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // o- + //////////////////////////////////////////////////////////// + else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.southNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.pathMark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1) { + eastTrials_path.add(transv.southNeighbor.toVertex); + transv = transv.eastNeighbor.toVertex; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // -o- + // | + //////////////////////////////////////////////////////////// + else if (transv.westNeighbor != null && transv.westNeighbor.direction != null + && !transv.westNeighbor.direction.isEmpty() + && transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + + && transv.northNeighbor.toVertex.mark != 1 + && transv.southNeighbor.toVertex.mark != 1 + + && transv.northNeighbor.toVertex.pathMark != 1 + && transv.southNeighbor.toVertex.pathMark != 1) { + eastTrials_path.add(transv.southNeighbor.toVertex); + transv = transv.northNeighbor.toVertex; + trial = 0; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // | + // o + //////////////////////////////////////////////////////////// + else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1 + && transv.eastNeighbor.toVertex.pathMark != 1) { + transv = transv.eastNeighbor.toVertex; + transv.pathMark = 1; + } + //////////////////////////////////////////////////////////// + // -o + // + //////////////////////////////////////////////////////////// + else if (transv.northNeighbor != null && transv.northNeighbor.direction != null + && !transv.northNeighbor.direction.isEmpty() + && transv.northNeighbor.toVertex.mark != 1 + && transv.northNeighbor.toVertex.pathMark != 1) { + transv = transv.northNeighbor.toVertex; + trial = 0; + transv.pathMark = 1; + trial = 0; + } + //////////////////////////////////////////////////////////// + // o- + // + //////////////////////////////////////////////////////////// + else if (transv.southNeighbor != null && transv.southNeighbor.direction != null + && !transv.southNeighbor.direction.isEmpty() + && transv.southNeighbor.toVertex.mark != 1 + && transv.pathMark != 1) { + int count = 0; + if (!eastTrials_path.isEmpty()) { + for (Vertex ok : eastTrials_path) { + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + transv = eastTrials_path.get(0); + transv.pathMark = 1; + eastTrials_path.remove(0); + } else { + notTransv = transv; + } + } + } + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// } - System.out.print(" \ni "); - //IF ONLY WEST DIRECTION EXIST, GO TO WEST TRIALZ - i++; - if (i > 10){ - System.out.print("END "); - break; + if (notTransv == transv && !transv.equals(v)) { + System.out.print("Equal"); + int count = 0; + if (trial == 0) { + if (!eastTrials_path.isEmpty()) { + for (Vertex ok : eastTrials_path) { + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + trial = 3; + transv = eastTrials_path.get(0); + notTransv = transv; + transv.pathMark = 1; + eastTrials_path.remove(0); + } + } + } else if (trial == 1) { + if (!northTrials_path.isEmpty()) { + for (Vertex ok : northTrials_path) { + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + trial = 0; + transv = northTrials_path.get(0); + notTransv = transv; + transv.pathMark = 1; + northTrials_path.remove(0); + } + } + } else if (trial == 2) { + if (!westTrials_path.isEmpty()) { + for (Vertex ok : westTrials_path) { + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + trial = 1; + transv = westTrials_path.get(0); + notTransv = transv; + transv.pathMark = 1; + westTrials_path.remove(0); + } + } + } else if (trial == 3) { + if (!southTrials_path.isEmpty()) { + for (Vertex ok : southTrials_path) { + System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + trial = 2; + transv = southTrials_path.get(0); + notTransv = transv; + transv.pathMark = 1; + southTrials_path.remove(0); + } + } + } } - */ System.out.print("{" + transv.tileLabel + "}, "); i++; - if (i > 20){ + if (i > vertices.size()) { + flag = 1; System.out.print(" END "); removePathMarkings(); break; } - }while(!transv.equals(v)); - - - - + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + } while (!transv.equals(v)); + if (flag == 1) { + System.out.print("did not find path"); + } else { + removePathMarkings(); + System.out.print("FOUND PATH"); + } - /* - do{ - if (transv.westNeighbor != null && transv.westNeighbor.direction != null && !transv.westNeighbor.direction.isEmpty() - && transv.westNeighbor.direction.equals("W") && direction.equals("N") && transv.westNeighbor.toVertex.mark != 1){ - direction = "W"; - System.out.print(" Go West "); - transv = transv.westNeighbor.toVertex; - System.out.print(transv.tileLabel + " "); - } - else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && !transv.southNeighbor.direction.isEmpty() - && transv.southNeighbor.direction.equals("S") && direction.equals("W") && transv.southNeighbor.toVertex.mark != 1){ - direction = "S"; - System.out.print(" Go South "); - transv = transv.southNeighbor.toVertex; - System.out.print(transv.tileLabel + " "); - } - else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && !transv.eastNeighbor.direction.isEmpty() - && transv.eastNeighbor.direction.equals("E") && direction.equals("S") && transv.eastNeighbor.toVertex.mark != 1){ - direction = "E"; - System.out.print(" Go East "); - transv = transv.eastNeighbor.toVertex; - System.out.print(transv.tileLabel + " "); - } - //this next half moves it forward more-> - else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && !transv.eastNeighbor.direction.isEmpty() - && transv.eastNeighbor.direction.equals("E") && direction.equals("E") && transv.eastNeighbor.toVertex.mark != 1){ - direction = "E"; - System.out.print(" Go East "); - transv = transv.eastNeighbor.toVertex; - System.out.print(transv.tileLabel + " "); - } - else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && !transv.southNeighbor.direction.isEmpty() - && transv.southNeighbor.direction.equals("S") && direction.equals("S") && transv.southNeighbor.toVertex.mark != 1){ - direction = "S"; - System.out.print(" Go South "); - transv = transv.southNeighbor.toVertex; - System.out.print(transv.tileLabel + " "); - } - else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && !transv.westNeighbor.direction.isEmpty() - && transv.westNeighbor.direction.equals("W") && direction.equals("W") && transv.westNeighbor.toVertex.mark != 1){ - direction = "W"; - System.out.print(" Go West "); - transv = transv.westNeighbor.toVertex; - System.out.print(transv.tileLabel + " "); - } - else if (transv.northNeighbor != null && transv.northNeighbor.direction != null && !transv.northNeighbor.direction.isEmpty() - && transv.northNeighbor.direction.equals("W") && direction.equals("W") && transv.northNeighbor.toVertex.mark != 1){ - direction = "W"; - System.out.print(" Go North "); - transv = transv.northNeighbor.toVertex; - System.out.print(transv.tileLabel + " "); - } - else{ - System.out.print(" Landed on: " + transv.tileLabel); - return; - } - }while(!transv.equals(v)); - */ } -} +} \ No newline at end of file From e8927021362b8d2b8641a4d0415e9f49c96c9905 Mon Sep 17 00:00:00 2001 From: AngelACantu Date: Sat, 24 Feb 2018 18:07:33 -0600 Subject: [PATCH 5/5] Find Faces 2. Deletes Duplicates, Handles multiple faces in one --- bonder | 233 ------------- final | 311 ------------------ save | 93 ------ .../asarg/polysim/models/base/Assembly.java | 1 + .../com/asarg/polysim/models/base/Graph.java | 200 +++++++---- test | 158 --------- tester | 163 --------- 7 files changed, 145 insertions(+), 1014 deletions(-) delete mode 100644 bonder delete mode 100644 final delete mode 100644 save delete mode 100644 test delete mode 100644 tester diff --git a/bonder b/bonder deleted file mode 100644 index 24ac20e..0000000 --- a/bonder +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - 2 - - - - - - e6e6e6 - o - - - -1.0 - -1 - - - - - e6e6e6 - n - q - - - -1.0 - -1 - - - - - e6e6e6 - p - q - - - -1.0 - -1 - - - - - e6e6e6 - h - m - p - i - - - -1.0 - -1 - - - - - e6e6e6 - l - n - m - - - -1.0 - -1 - - - - - e6e6e6 - k - o - l - g - - - -1.0 - -1 - - - - - e6e6e6 - k - j - - - -1.0 - -1 - - - - - e6e6e6 - j - h - - - -1.0 - -1 - - - - - e6e6e6 - d - i - - - -1.0 - -1 - - - - - e6e6e6 - h - g - f - e - - - -1.0 - -1 - - - - - e6e6e6 - e - d - c - - - -1.0 - -1 - - - - - e6e6e6 - c - b - - - -1.0 - -1 - - - - - e6e6e6 - b - a - - - -1.0 - -1 - - - - - e6e6e6 - a - - - -1.0 - -1 - - diff --git a/final b/final deleted file mode 100644 index 1a020b7..0000000 --- a/final +++ /dev/null @@ -1,311 +0,0 @@ - - - - - - 2 - - - - 1 - - - - 1 - - - - 2 - - - - 2 - - - - 1 - - - - 1 - - - - 1 - - - - 2 - - - - 2 - - - - 2 - - - - 1 - - - - 1 - - - - 1 - - - - 2 - - - - 1 - - - - 2 - - - - - - e6e6e6 - r - d0 - r - u0 - - - -1.0 - -1 - - - - - e6e6e6 - p - u3 - p - d0 - - - -1.0 - -1 - - - - - CCFFFF - g - u2 - g - u2 - - - -1.0 - -1 - - - - - B3E6E6 - g - u3 - g - u3 - - - -1.0 - -1 - - - - - E6804D - g - h3 - r - u3 - - - -1.0 - -1 - - - - - E6994D - g - u2 - p - h3 - - - -1.0 - -1 - - - - - CCE6FF - g - u0 - g - u0 - - - -1.0 - -1 - - - - - 99CCCC - g - u1 - g - u1 - - - -1.0 - -1 - - - - - E64D4D - g - h2 - r - u2 - - - -1.0 - -1 - - - - - E64D4D - g - u1 - p - h2 - - - -1.0 - -1 - - - - - 4D3399 - g - h1 - r - u1 - - - -1.0 - -1 - - - - - 4D3399 - g - u0 - p - h1 - - - -1.0 - -1 - - - - - FFFF66 - p - c3 - c0 - - - -1.0 - -1 - - - - - FFFF80 - g - c2 - c3 - - - -1.0 - -1 - - - - - FFFF99 - g - c1 - c2 - - - -1.0 - -1 - - - - - FFFFCC - r - c0 - c1 - - - -1.0 - -1 - - - - - 336633 - s2 - u0 - - - -1.0 - -1 - - - - - 336633 - s2 - s1 - u0 - - - -1.0 - -1 - - - - - 336633 - s1 - c1 - - - -1.0 - -1 - - diff --git a/save b/save deleted file mode 100644 index 63931ed..0000000 --- a/save +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - 2 - - - - 1 - - - - - - e6e6e6 - - - -1.0 - -1 - - - - - e6e6e6 - d - d - d - - - -1.0 - -1 - - - - - e6e6e6 - s1 - d - a1 - - - -1.0 - -1 - - - - - e6e6e6 - a1 - a1 - - - - -1.0 - -1 - - - - - e6e6e6 - a1 - - - - - e6e6e6 - d - d - - - - - e6e6e6 - d - - - - - e6e6e6 - d - - - - - e6e6e6 - d - - - -1.0 - -1 - - diff --git a/src/main/java/com/asarg/polysim/models/base/Assembly.java b/src/main/java/com/asarg/polysim/models/base/Assembly.java index 679c6bf..b0ddfe9 100644 --- a/src/main/java/com/asarg/polysim/models/base/Assembly.java +++ b/src/main/java/com/asarg/polysim/models/base/Assembly.java @@ -106,6 +106,7 @@ else if (v.location.getSouth().equals(vertex.location)){ } bondGraph.printVertices(); bondGraph.makeDualGraph(); + bondGraph.printAmount(); } //change tile system stub public void changeTileSystem(TileSystem newTS) { diff --git a/src/main/java/com/asarg/polysim/models/base/Graph.java b/src/main/java/com/asarg/polysim/models/base/Graph.java index 264ce65..bee8542 100644 --- a/src/main/java/com/asarg/polysim/models/base/Graph.java +++ b/src/main/java/com/asarg/polysim/models/base/Graph.java @@ -1,13 +1,15 @@ package com.asarg.polysim.models.base; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; public class Graph { public List vertices = new ArrayList<>(); - public List faceVertices = new ArrayList<>(); - + public ArrayList> faceVertices = new ArrayList>(); + public int face_amount = 0; public class Vertex { public String tileLabel = new String(); ; @@ -102,19 +104,61 @@ public void makeDualGraph() { } public void getFaces() { + ArrayList buffer = new ArrayList(); for (Vertex v : vertices) { if (v.neighbors.size() == 1) { - System.out.print(" " + v.tileLabel + " A LONER TILE\n "); + //System.out.print(" " + v.tileLabel + " A LONER TILE\n "); } else { for (Edge e : v.neighbors) { if (e.direction.equals("N")) { - theTrials(v, e); + buffer = theTrials(v, e); + if (!buffer.isEmpty()){ + faceVertices.add(buffer); + } } } } } + //remove redundant + if (!faceVertices.isEmpty()){ + int flag = 0; + ArrayList> path = new ArrayList>(); + path.add(faceVertices.get(0)); + for (ArrayList firstPath : faceVertices){ + for (ArrayList secondPath : path){ + if (listEqualsIgnoreOrder(secondPath, firstPath)){ + flag = 1; + } + } + if (flag == 0){ + path.add(firstPath); + } + else{ + flag = 0; + } + } + faceVertices = path; + } + printPath(); + } + public static boolean listEqualsIgnoreOrder(ArrayList list1, ArrayList list2) { + return new HashSet<>(list1).equals(new HashSet<>(list2)); + } + public void printPath(){ + if (!faceVertices.isEmpty()){ + for (ArrayList p : faceVertices) { + System.out.print("Path for {" + p.get(0).tileLabel + "} = { "); + for (Vertex v : p){ + System.out.print(v.tileLabel + ", "); + } + System.out.println("};"); + } + } + System.out.println("Face amount: " + faceVertices.size()); + } + public void printAmount(){ + System.out.print("Amount of faces:" + face_amount); } - public int markHairs() { int minimum_edge_amount = 5; for (Vertex v : vertices) { @@ -130,17 +174,9 @@ public int markHairs() { for (Vertex v : vertices) { if (v.edgeAmount <= minimum_edge_amount && v.mark != 1) { minimum_edge_amount = v.edgeAmount; - System.out.print(minimum_edge_amount); } - System.out.print("} THIS: " + v.tileLabel + ", #" + v.edgeAmount + " {"); } - //print the mark ones - for (Vertex v : vertices) { - if (v.mark == 1) { - System.out.print("} THIS GUY IS MARKED: {" + v.tileLabel + "} "); - } - } return minimum_edge_amount; } @@ -152,9 +188,10 @@ public void removePathMarkings() { } - public void theTrials(Vertex v, Edge start) { + public ArrayList theTrials(Vertex v, Edge start) { Vertex transv = new Vertex(); Vertex notTransv = new Vertex(); + int round = 0; //north trial = 0 //west trial = 1 //south trial = 2 @@ -166,22 +203,27 @@ public void theTrials(Vertex v, Edge start) { List southTrials_path = new ArrayList(); List eastTrials_path = new ArrayList(); + ArrayList finalPath = new ArrayList(); + finalPath.add(v); transv = start.toVertex; + finalPath.add(transv); notTransv = v; String direction = "N"; - System.out.print("\nI am target tile: " + v.tileLabel + " and I'm at " + transv.tileLabel + " "); + //System.out.print("\nI am target tile: " + v.tileLabel + " and I'm at " + transv.tileLabel + " "); //this is the north trial //if both a west, east, and north, save east and north trial but go to the west trial //if west trial fails, return to east or north, preferably north, saved and continue NORTH trial int i = 0; + // System.out.print("\nFirst Tile " + v.tileLabel + " -> "); do { - System.out.print(" " + i + " "); + //System.out.print(" AT: {" + transv.tileLabel + "}<-R: " + round + " T: " + trial + "}"); + //System.out.print(" " + i + " "); //////////////////////////////////////////////////////////// //THE NORTH TRIALS////////////////////////////////////////// if (trial == 0) { - System.out.print("North Trials\n"); + //System.out.print("North Trials\n"); //////////////////////////////////////////////////////////// ////////////////// // | @@ -204,6 +246,7 @@ public void theTrials(Vertex v, Edge start) { northTrials_path.add(transv.northNeighbor.toVertex); northTrials_path.add(transv.eastNeighbor.toVertex); transv = transv.westNeighbor.toVertex; + finalPath.add(transv); trial = 1; transv.pathMark = 1; } @@ -221,6 +264,7 @@ else if (transv.northNeighbor != null && transv.northNeighbor.direction != null && transv.northNeighbor.toVertex.pathMark != 1) { northTrials_path.add(transv.northNeighbor.toVertex); transv = transv.westNeighbor.toVertex; + finalPath.add(transv); trial = 1; transv.pathMark = 1; } @@ -238,6 +282,7 @@ else if (transv.northNeighbor != null && transv.northNeighbor.direction != null && transv.northNeighbor.toVertex.pathMark != 1) { northTrials_path.add(transv.eastNeighbor.toVertex); transv = transv.northNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; } //////////////////////////////////////////////////////////// @@ -257,6 +302,7 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && transv.westNeighbor.toVertex.pathMark != 1) { northTrials_path.add(transv.eastNeighbor.toVertex); transv = transv.westNeighbor.toVertex; + finalPath.add(transv); trial = 1; transv.pathMark = 1; } @@ -269,6 +315,7 @@ else if (transv.northNeighbor != null && transv.northNeighbor.direction != null && transv.northNeighbor.toVertex.mark != 1 && transv.northNeighbor.toVertex.pathMark != 1) { transv = transv.northNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; } //////////////////////////////////////////////////////////// @@ -280,6 +327,7 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && transv.westNeighbor.toVertex.mark != 1 && transv.westNeighbor.toVertex.pathMark != 1) { transv = transv.westNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; trial = 1; } @@ -290,33 +338,39 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && !transv.eastNeighbor.direction.isEmpty() && transv.eastNeighbor.toVertex.mark != 1 - && transv.pathMark != 1) { - int count = 0; - if (!northTrials_path.isEmpty()) { - for (Vertex ok : northTrials_path) { - System.out.print(ok.tileLabel + " "); - count = count + 1; - } - if (count >= 1) { - transv = northTrials_path.get(0); - transv.pathMark = 1; - northTrials_path.remove(0); - } else { - notTransv = transv; + && transv.pathMark != 1 + && round == 0) { + int count = 0; + if (!northTrials_path.isEmpty()) { + for (Vertex ok : northTrials_path) { + //System.out.print(ok.tileLabel + " "); + count = count + 1; + } + if (count >= 1) { + transv = northTrials_path.get(0); + finalPath.remove(finalPath.size() - 1); + finalPath.add(transv); + transv.pathMark = 1; + northTrials_path.remove(0); + } else { + notTransv = transv; + } } - } } + else if (round != 0 && transv.eastNeighbor != null && transv.eastNeighbor.direction != null + && !transv.eastNeighbor.direction.isEmpty() + && transv.eastNeighbor.toVertex.mark != 1) { + transv = transv.eastNeighbor.toVertex; + trial = 3; + } + //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// } else if (trial == 1) { - System.out.print("West Trials\n"); + //System.out.print("West Trials\n"); //////////////////////////////////////////////////////////// //THE WEST TRIALS////////////////////////////////////////// //////////////////////////////////////////////////////////// - ////////////////// - // - // - //////////////////////////////////////////////////////////// if (transv.westNeighbor != null && transv.westNeighbor.direction != null && !transv.westNeighbor.direction.isEmpty() && transv.southNeighbor != null && transv.southNeighbor.direction != null @@ -334,6 +388,7 @@ else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null westTrials_path.add(transv.westNeighbor.toVertex); westTrials_path.add(transv.northNeighbor.toVertex); transv = transv.southNeighbor.toVertex; + finalPath.add(transv); trial = 2; transv.pathMark = 1; } @@ -353,6 +408,7 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && transv.westNeighbor.toVertex.pathMark != 1) { westTrials_path.add(transv.westNeighbor.toVertex); transv = transv.southNeighbor.toVertex; + finalPath.add(transv); trial = 2; transv.pathMark = 1; } @@ -370,7 +426,7 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && transv.westNeighbor.toVertex.pathMark != 1) { westTrials_path.add(transv.northNeighbor.toVertex); transv = transv.westNeighbor.toVertex; - + finalPath.add(transv); transv.pathMark = 1; } //////////////////////////////////////////////////////////// @@ -392,6 +448,7 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && transv.southNeighbor.toVertex.pathMark != 1) { westTrials_path.add(transv.northNeighbor.toVertex); transv = transv.southNeighbor.toVertex; + finalPath.add(transv); trial = 2; transv.pathMark = 1; } @@ -404,6 +461,7 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && transv.westNeighbor.toVertex.mark != 1 && transv.westNeighbor.toVertex.pathMark != 1) { transv = transv.westNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; } //////////////////////////////////////////////////////////// @@ -415,6 +473,7 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && transv.southNeighbor.toVertex.mark != 1 && transv.southNeighbor.toVertex.pathMark != 1) { transv = transv.southNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; trial = 2; } @@ -429,11 +488,13 @@ else if (transv.northNeighbor != null && transv.northNeighbor.direction != null int count = 0; if (!westTrials_path.isEmpty()) { for (Vertex ok : westTrials_path) { - System.out.print(ok.tileLabel + " "); + // System.out.print(ok.tileLabel + " "); count = count + 1; } if (count >= 1) { transv = westTrials_path.get(0); + finalPath.remove(finalPath.size() - 1); + finalPath.add(transv); transv.pathMark = 1; westTrials_path.remove(0); } else { @@ -444,7 +505,7 @@ else if (transv.northNeighbor != null && transv.northNeighbor.direction != null //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// } else if (trial == 2) { - System.out.print("South Trials\n"); + //System.out.print("South Trials\n"); //////////////////////////////////////////////////////////// //THE SOUTH TRIALS////////////////////////////////////////// //////////////////////////////////////////////////////////// @@ -469,6 +530,7 @@ else if (transv.northNeighbor != null && transv.northNeighbor.direction != null southTrials_path.add(transv.westNeighbor.toVertex); southTrials_path.add(transv.southNeighbor.toVertex); transv = transv.eastNeighbor.toVertex; + finalPath.add(transv); trial = 3; transv.pathMark = 1; } @@ -488,6 +550,7 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && transv.southNeighbor.toVertex.pathMark != 1) { southTrials_path.add(transv.southNeighbor.toVertex); transv = transv.eastNeighbor.toVertex; + finalPath.add(transv); trial = 3; transv.pathMark = 1; } @@ -507,6 +570,7 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && transv.southNeighbor.toVertex.pathMark != 1) { southTrials_path.add(transv.northNeighbor.toVertex); transv = transv.southNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; } //////////////////////////////////////////////////////////// @@ -528,6 +592,7 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && transv.westNeighbor.toVertex.pathMark != 1) { southTrials_path.add(transv.westNeighbor.toVertex); transv = transv.eastNeighbor.toVertex; + finalPath.add(transv); trial = 3; transv.pathMark = 1; } @@ -540,6 +605,7 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null && transv.southNeighbor.toVertex.mark != 1 && transv.southNeighbor.toVertex.pathMark != 1) { transv = transv.southNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; } //////////////////////////////////////////////////////////// @@ -551,9 +617,9 @@ else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && transv.eastNeighbor.toVertex.mark != 1 && transv.eastNeighbor.toVertex.pathMark != 1) { transv = transv.eastNeighbor.toVertex; + finalPath.add(transv); trial = 3; transv.pathMark = 1; - trial = 3; } //////////////////////////////////////////////////////////// // o- @@ -566,11 +632,13 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null int count = 0; if (!southTrials_path.isEmpty()) { for (Vertex ok : southTrials_path) { - System.out.print(ok.tileLabel + " "); + //System.out.print(ok.tileLabel + " "); count = count + 1; } if (count >= 1) { transv = southTrials_path.get(0); + finalPath.remove(finalPath.size() - 1); + finalPath.add(transv); transv.pathMark = 1; southTrials_path.remove(0); } else { @@ -581,7 +649,8 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// } else if (trial == 3) { - System.out.print("East Trials\n"); + round++; + //System.out.print("East Trials\n"); //////////////////////////////////////////////////////////// //THE EAST TRIALS////////////////////////////////////////// //////////////////////////////////////////////////////////// @@ -606,6 +675,7 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null eastTrials_path.add(transv.eastNeighbor.toVertex); eastTrials_path.add(transv.southNeighbor.toVertex); transv = transv.northNeighbor.toVertex; + finalPath.add(transv); trial = 0; transv.pathMark = 1; } @@ -625,6 +695,7 @@ else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && transv.eastNeighbor.toVertex.pathMark != 1) { eastTrials_path.add(transv.eastNeighbor.toVertex); transv = transv.northNeighbor.toVertex; + finalPath.add(transv); trial = 0; transv.pathMark = 1; } @@ -642,6 +713,7 @@ else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && transv.eastNeighbor.toVertex.pathMark != 1) { eastTrials_path.add(transv.southNeighbor.toVertex); transv = transv.eastNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; } //////////////////////////////////////////////////////////// @@ -662,6 +734,7 @@ else if (transv.westNeighbor != null && transv.westNeighbor.direction != null && transv.southNeighbor.toVertex.pathMark != 1) { eastTrials_path.add(transv.southNeighbor.toVertex); transv = transv.northNeighbor.toVertex; + finalPath.add(transv); trial = 0; transv.pathMark = 1; } @@ -674,6 +747,7 @@ else if (transv.eastNeighbor != null && transv.eastNeighbor.direction != null && transv.eastNeighbor.toVertex.mark != 1 && transv.eastNeighbor.toVertex.pathMark != 1) { transv = transv.eastNeighbor.toVertex; + finalPath.add(transv); transv.pathMark = 1; } //////////////////////////////////////////////////////////// @@ -685,6 +759,7 @@ else if (transv.northNeighbor != null && transv.northNeighbor.direction != null && transv.northNeighbor.toVertex.mark != 1 && transv.northNeighbor.toVertex.pathMark != 1) { transv = transv.northNeighbor.toVertex; + finalPath.add(transv); trial = 0; transv.pathMark = 1; trial = 0; @@ -700,11 +775,13 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null int count = 0; if (!eastTrials_path.isEmpty()) { for (Vertex ok : eastTrials_path) { - System.out.print(ok.tileLabel + " "); + //System.out.print(ok.tileLabel + " "); count = count + 1; } if (count >= 1) { transv = eastTrials_path.get(0); + finalPath.remove(finalPath.size() - 1); + finalPath.add(transv); transv.pathMark = 1; eastTrials_path.remove(0); } else { @@ -715,13 +792,14 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null //////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////// } + if (notTransv == transv && !transv.equals(v)) { - System.out.print("Equal"); + // System.out.print("Equal"); int count = 0; if (trial == 0) { if (!eastTrials_path.isEmpty()) { for (Vertex ok : eastTrials_path) { - System.out.print(ok.tileLabel + " "); + // System.out.print(ok.tileLabel + " "); count = count + 1; } if (count >= 1) { @@ -735,7 +813,7 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null } else if (trial == 1) { if (!northTrials_path.isEmpty()) { for (Vertex ok : northTrials_path) { - System.out.print(ok.tileLabel + " "); + // System.out.print(ok.tileLabel + " "); count = count + 1; } if (count >= 1) { @@ -749,7 +827,7 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null } else if (trial == 2) { if (!westTrials_path.isEmpty()) { for (Vertex ok : westTrials_path) { - System.out.print(ok.tileLabel + " "); + // System.out.print(ok.tileLabel + " "); count = count + 1; } if (count >= 1) { @@ -763,7 +841,7 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null } else if (trial == 3) { if (!southTrials_path.isEmpty()) { for (Vertex ok : southTrials_path) { - System.out.print(ok.tileLabel + " "); + // System.out.print(ok.tileLabel + " "); count = count + 1; } if (count >= 1) { @@ -776,26 +854,36 @@ else if (transv.southNeighbor != null && transv.southNeighbor.direction != null } } } - System.out.print("{" + transv.tileLabel + "}, "); + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////// + //System.out.print("{" + transv.tileLabel + "}, "); i++; if (i > vertices.size()) { flag = 1; - System.out.print(" END "); + //System.out.print(" END "); removePathMarkings(); break; } - //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////// } while (!transv.equals(v)); if (flag == 1) { - System.out.print("did not find path"); + System.out.print("did not find path\n" + ", trial ended= " + trial + ", round =" + round); + for (Vertex d : finalPath){ + System.out.print(" " + d.tileLabel + " " ); + } + removePathMarkings(); + finalPath.clear(); + return finalPath; } else { + //printPath(finalPath); removePathMarkings(); - System.out.print("FOUND PATH"); + //face_amount++; + //System.out.print("FOUND PATH\n"); + return finalPath; } } + } \ No newline at end of file diff --git a/test b/test deleted file mode 100644 index 91e661f..0000000 --- a/test +++ /dev/null @@ -1,158 +0,0 @@ - - - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - -1.0 - -1 - - diff --git a/tester b/tester deleted file mode 100644 index 71311f6..0000000 --- a/tester +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - 1 - - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - - - e6e6e6 - - - -1.0 - -1 - -