import java.util.List; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; import java.util.Stack; import java.util.function.Function; /** * */ /** * @author your name(s) here. * Extra Credit Options Implemented, if any: (mention them here.) * * Solution to Assignment 5 in CSE 373, Autumn 2016 * University of Washington. * * (Based on starter code v1.3. By Steve Tanimoto.) * * Java version 8 or higher is recommended. * */ // Here is the main application class: public class ExploredGraph { Set Ve; // collection of explored vertices Set Ee; // collection of explored edges public ExploredGraph() { Ve = new LinkedHashSet(); Ee = new LinkedHashSet(); } public void initialize() { // Implement this } public int nvertices() {return 0;} // Implement this. public int nedges() {return 0;} // Implement this. public void idfs(Vertex vi, Vertex vj) {} // Implement this. (Iterative Depth-First Search) public void bfs(Vertex vi, Vertex vj) {} // Implement this. (Breadth-First Search) public ArrayList retrievePath(Vertex vi) {return null;} // Implement this. public ArrayList shortestPath(Vertex vi, Vertex vj) {return null;} // Implement this. public Set getVertices() {return Ve;} public Set getEdges() {return Ee;} /** * @param args */ public static void main(String[] args) { ExploredGraph eg = new ExploredGraph(); // Test the vertex constructor: Vertex v0 = eg.new Vertex("[[4,3,2,1],[],[]]"); System.out.println(v0); // Add your own tests here. // The autograder code will be used to test your basic functionality later. } class Vertex { ArrayList> pegs; // Each vertex will hold a Towers-of-Hanoi state. // There will be 3 pegs in the standard version, but more if you do extra credit option A5E1. // Constructor that takes a string such as "[[4,3,2,1],[],[]]": public Vertex(String vString) { String[] parts = vString.split("\\],\\["); pegs = new ArrayList>(3); for (int i=0; i<3;i++) { pegs.add(new Stack()); try { parts[i]=parts[i].replaceAll("\\[",""); parts[i]=parts[i].replaceAll("\\]",""); List al = new ArrayList(Arrays.asList(parts[i].split(","))); System.out.println("ArrayList al is: "+al); Iterator it = al.iterator(); while (it.hasNext()) { String item = it.next(); if (!item.equals("")) { System.out.println("item is: "+item); pegs.get(i).push(Integer.parseInt(item)); } } } catch(NumberFormatException nfe) { nfe.printStackTrace(); } } } public String toString() { String ans = "["; for (int i=0; i<3; i++) { ans += pegs.get(i).toString().replace(" ", ""); if (i<2) { ans += ","; } } ans += "]"; return ans; } } class Edge { public Edge(Vertex vi, Vertex vj) { // Add whatever you need to here. } } class Operator { private int i, j; public Operator(int i, int j) { // Constructor for operators. this.i = i; this.j = j; } public boolean precondition(Vertex v) { // TODO: Add code that will determine whether or not this // operator is applicable to this vertex. return false; // Placeholder. Change this. } public Vertex transition(Vertex v) { // TODO: Add code to return a "successor" of v, according // to this operator. return null; // Placeholder. change this. } public String toString() { // TODO: Add code to return a string good enough // to distinguish different operators return ""; } } }