-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public abstract class A_Star extends GraphSearchAlgorithm{ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import java.util.*; | ||
|
||
public class BFS extends GraphSearchAlgorithm{ | ||
|
||
@Override | ||
AbstractCollection<Node> initOpen() { | ||
return new LinkedList<>(); | ||
} | ||
|
||
@Override | ||
Node nextNode(AbstractCollection open) throws Exception { | ||
if(open instanceof Queue) { | ||
return ((Queue<Node>)open).remove(); | ||
} else{ | ||
throw new Exception("Krivog tipa je open"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.AbstractCollection; | ||
import java.util.Stack; | ||
|
||
public class DFS extends GraphSearchAlgorithm{ | ||
|
||
@Override | ||
AbstractCollection<Node> initOpen() { | ||
return new Stack<>(); | ||
} | ||
|
||
@Override | ||
Node nextNode(AbstractCollection open) throws Exception { | ||
if(open instanceof Stack) { | ||
return ((Stack<Node>)open).pop(); | ||
} else{ | ||
throw new Exception("Krivog tipa je open"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import java.util.*; | ||
|
||
abstract class GraphSearchAlgorithm { | ||
|
||
public List<Node> run(Node s0, SearchProblem problem) throws Exception { | ||
Node node = s0; | ||
AbstractCollection<Node> open = initOpen(); | ||
open.add(node); | ||
Set<Node> closed = new HashSet<>(); | ||
while(! open.isEmpty()){ | ||
node = nextNode(open); | ||
if(problem.isGoalState(node)){ | ||
return node.path(); | ||
} | ||
if(!closed.contains(node)){ | ||
closed.add(node); | ||
Map<Node, Double> succ = problem.successors(node); | ||
for(Node m : succ.keySet()){ | ||
//if(m.getCost() == null || m.getCost() > node.getCost() + succ.get(m)){ | ||
m.setCost(node.getCost() + succ.get(m)); | ||
open.add(m); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
abstract AbstractCollection<Node> initOpen(); | ||
|
||
abstract Node nextNode(AbstractCollection open) throws Exception; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Problem[] problems = Reader.getProblems(); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
class Node { | ||
|
||
private String name; | ||
private Node parent; | ||
private boolean isRootNode; | ||
private Double cost; | ||
|
||
public Node(String name, Node parent, boolean isRootNode){ | ||
this.name = name; | ||
this.parent = parent; | ||
this.isRootNode = isRootNode; | ||
} | ||
|
||
List<Node> path() { | ||
List<Node> list; | ||
if(isRootNode) { | ||
list = new LinkedList<>(); | ||
} else { | ||
list = parent.path(); | ||
} | ||
list.add(0, this); | ||
return list; | ||
} | ||
|
||
public boolean isRootNode() { | ||
return isRootNode; | ||
} | ||
|
||
public Node getParent() { | ||
return parent; | ||
} | ||
|
||
public String getName(){ | ||
return name; | ||
} | ||
|
||
public void setCost(Double cost){ | ||
this.cost = cost; | ||
} | ||
|
||
public Double getCost(){ | ||
return cost; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
class Problem { | ||
|
||
Map<Node, Map<Node, Double>> successors; | ||
|
||
Problem(Map<Node, Map<Node, Double>> successors){ | ||
this.successors = successors; | ||
} | ||
|
||
boolean isGoalState(Node n) { | ||
return n.isRootNode(); | ||
} | ||
|
||
Map<Node, Double> successors(Node n) { | ||
return successors.get(n); | ||
} | ||
//!!!!pospremaj svako stanje jednom u memoriju za svaki par stanje-roditelj, da se moze koristiti path() | ||
//da vrati put do stanja | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Reader { | ||
static Problem[] getProblems(){ | ||
return null; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
class SearchProblem extends Problem { | ||
|
||
SearchProblem(Map<Node, Map<Node, Double>> successors) { | ||
super(successors); | ||
} | ||
} |