Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
eliztekcan committed Mar 9, 2017
2 parents 370a35e + c0e8d9f commit 6742653
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 100 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
<groupId>uni.bilkent.hai</groupId>
<artifactId>boat-soldiers-problem</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>


</project>
13 changes: 7 additions & 6 deletions src/main/java/uni/bilkent/hai/GraphGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ public GraphGenerator()
{
stateGenerator = new StateGenerator();
List<State> neighborstates;
nodes = "[ {";
edges = "[ {";
nodes = "[ ";
edges = "[ ";
states = stateGenerator.getStates();
// TODO: give classes property to goal & start nodes
for(int i = 0; i < states.size(); i++){
State curState = states.get(i);
neighborstates = curState.getNeighborStates();
nodes += "\"data\": { \"id\": \"" + curState.getid() + "\",";
nodes += "{ \"data\": { \"id\": \"" + curState.getid() + "\",";
nodes += "\"content\": \"((" ;

if(curState.getStart().getNumberOfBoys() != 0)
Expand Down Expand Up @@ -62,7 +63,7 @@ public GraphGenerator()
nodes += ",";
}
for(int j = 0; j < neighborstates.size(); j++) {
edges += "\"data\": { \"source\": \"" + curState.getid() + "\",\"target\": "
edges += "{ \"data\": { \"source\": \"" + curState.getid() + "\",\"target\": \""
+ neighborstates.get(j).getid() + "\" } },";
}

Expand All @@ -76,8 +77,8 @@ public GraphGenerator()

public void JSONFile(){
try {
File file = new File("edges.json");
File file2 = new File("nodes.json");
File file = new File("web/edges.json");
File file2 = new File("web/nodes.json");
file.createNewFile();
FileWriter fileWriter = new FileWriter(file);
FileWriter fileWriter2 = new FileWriter(file2);
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/uni/bilkent/hai/GraphTraverser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package uni.bilkent.hai;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
* Created by deniz on 09/03/17.
*/
public class GraphTraverser
{
public GraphTraverser()
{
StateGenerator sg = new StateGenerator();
State start = sg.getStartState();
StateTree tree = new StateTree( start);

Stack<State> path = new Stack<State>();
List<State> visited = new ArrayList<State>();

visited.add( start);
path.add( start);

while ( !path.isEmpty())
{
State cur = path.peek();
System.out.println( cur);
List<State> neighborStates = cur.getNeighborStates();
boolean deadEnd = true;

for ( State s : neighborStates)
{
if ( !visited.contains( s))
{
path.push(s);
visited.add( s);
deadEnd = false;
break;
}
}

if ( deadEnd)
path.pop();
}

System.out.println( visited.size());
}

public static void main( String[] args)
{
GraphTraverser gt = new GraphTraverser();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package uni.bilkent.hai.graph.GUI;
package uni.bilkent.hai;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.stage.Stage;
import uni.bilkent.hai.graph.Graph;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uni/bilkent/hai/SideOfRiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public void setBoys(List<Boy> boys) {
@Override
public String toString() {
return "SideOfRiver{" +
"soldiers=" + soldiers +
", boys=" + boys +
"soldiers = " + soldiers +
", boys = " + boys +
'}';
}
}
2 changes: 1 addition & 1 deletion src/main/java/uni/bilkent/hai/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String toString() {
+ "Start soldiers: " + start.getSoldiers().size() + "\n"
+ "Goal boys: " + goal.getBoys().size() + "\n"
+ "Goal soldiers: " + goal.getSoldiers().size() + "\n"
+ "Side of boat: " + boat.getRiverSide();
+ "Side of boat: " + boat.getRiverSide() + "\n";
}

public Boat getBoat() {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/uni/bilkent/hai/StateGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public StateGenerator()
states.add(new State(numberOfBoys - i, numberOfSoldiers - j, i, j, boatSide));

configureLinks();
removeNeigborlessStates();
// removeNeigborlessStates();
}

private void configureLinks()
Expand Down Expand Up @@ -68,6 +68,8 @@ private void removeNeigborlessStates()
states.remove( s);
}

public State getStartState() { return states.get(0); }

public int getNumberOfBoys() {
return numberOfBoys;
}
Expand Down
33 changes: 17 additions & 16 deletions src/main/java/uni/bilkent/hai/StateTree.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
package uni.bilkent.hai;

import java.util.ArrayList;
import java.util.List;

/**
* Created by eliztekcan on 9.03.2017.
*/
public class StateTree{
public class StateTree
{
private Node root;

public StateTree( State s){
root = new Node( s);
}

public Node getRoot() {
return root;
}

public void setRoot(Node root) {
public void setRoot( Node root) {
this.root = root;
}

public StateTree(State s){
root = new Node();
}
public static class Node {

public static class Node{
private Node parent;
private List<Node> children;
private State state;

public Node getParent() {
return parent;
public Node( State s)
{
state = s;
children = new ArrayList<Node>();
}

public State getState() { return state; }

public List<Node> getChildren() {
return children;
}

public void setChildren(List<Node> children) {
this.children = children;
}

public void setParent(Node parent) {
this.parent = parent;
}
public void addChild( Node child) { children.add( child); };
}
}
17 changes: 13 additions & 4 deletions src/main/java/uni/bilkent/hai/graph/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,24 @@ public class Graph extends Parent {
private WebEngine webEngine;
private boolean ready;


//####################################################################

/**
* Constructor
* Initiation of following methods
* initMap() iniCommunication() getChildren().add(webView)
*/
public Graph() {
initMap();
initCommunication();
Screen screen = Screen.getPrimary();
webView.setPrefSize(screen.getBounds().getWidth(),screen.getBounds().getHeight() - 100);
getChildren().add(webView); // Will be change as JavaFx Elements change

// invokeJS("$('body').html(\"qwewqeqw\")s");
}


/**
* Initialize the Map
* Creates a webview which is for calling google map from html.
Expand All @@ -39,15 +45,18 @@ private void initMap() {
//####################### Initialize Web View #######################
webView = new WebView();
webEngine = webView.getEngine();
webEngine.setJavaScriptEnabled(true);
webEngine.load(getClass().getResource("web/index.html").toExternalForm());
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>()
{
@Override
public void changed(final ObservableValue<? extends Worker.State> observableValue,
final Worker.State oldState,
final Worker.State newState)
{
if (newState == Worker.State.SUCCEEDED)
{
System.out.println("readyy");
ready = true;
}
}
Expand All @@ -64,6 +73,7 @@ public void changed(final ObservableValue<? extends Worker.State> observableValu
private void initCommunication() {
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>()
{
@Override
public void changed(final ObservableValue<? extends Worker.State> observableValue,
final Worker.State oldState,
final Worker.State newState)
Expand Down Expand Up @@ -91,6 +101,7 @@ private void invokeJS(final String jsCode) {
// Check again, If everything is ok, eval the script
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>()
{
@Override
public void changed(final ObservableValue<? extends Worker.State> observableValue,
final Worker.State oldState,
final Worker.State newState)
Expand All @@ -104,6 +115,4 @@ public void changed(final ObservableValue<? extends Worker.State> observableValu
}
}



}
}
60 changes: 0 additions & 60 deletions src/main/java/uni/bilkent/hai/graph/web/code.js

This file was deleted.

Loading

0 comments on commit 6742653

Please sign in to comment.