-
Notifications
You must be signed in to change notification settings - Fork 2
Resenje druge vezbe #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ra133-2013
wants to merge
1
commit into
ftn-ai-lab:master
Choose a base branch
from
ra133-2013:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 11.00 | ||
# Visual Studio 2010 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PretrageOsnovno", "PretrageOsnovno\PretrageOsnovno.csproj", "{C78D10E9-7D95-40AA-B84A-2931B8DDC038}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x86 = Debug|x86 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C78D10E9-7D95-40AA-B84A-2931B8DDC038}.Debug|x86.ActiveCfg = Debug|x86 | ||
{C78D10E9-7D95-40AA-B84A-2931B8DDC038}.Debug|x86.Build.0 = Debug|x86 | ||
{C78D10E9-7D95-40AA-B84A-2931B8DDC038}.Release|x86.ActiveCfg = Release|x86 | ||
{C78D10E9-7D95-40AA-B84A-2931B8DDC038}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace PretrageOsnovno | ||
{ | ||
class AStarSearch | ||
{ | ||
|
||
public State Search(string startNodeName, string endNodeName,bool dodatni) | ||
{ | ||
Node startNode = Program.instance.graph[startNodeName]; | ||
Node endNode = Program.instance.graph[endNodeName]; | ||
|
||
List<State> stanjaZaObradu = new List<State>(); | ||
|
||
stanjaZaObradu.Add(new State(startNode)); | ||
|
||
while (stanjaZaObradu.Count > 0) | ||
{ | ||
State naObradi = stanjaZaObradu[0]; | ||
stanjaZaObradu.Remove(naObradi); | ||
|
||
if (naObradi.Node.Name == endNode.Name) | ||
{ | ||
return naObradi; | ||
} | ||
else | ||
{ | ||
List<State> mogucaSledecaStanja = naObradi.children(); | ||
stanjaZaObradu.InsertRange(0, mogucaSledecaStanja); | ||
sortiraj(stanjaZaObradu,endNode,dodatni); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
|
||
// metoda koja sortira listu u rastucem redosledu zbira cene i heuristike | ||
private void sortiraj(List<State> lista, Node endNode,bool dodatni) | ||
{ | ||
|
||
if(lista.Count>0){ | ||
//ukoliko ima sta da sortira | ||
//bubble sort | ||
bool flag = false; | ||
for (int i = 1; (i <= (lista.Count - 1))&&flag; i++) | ||
{ | ||
for (int j = 0; j < (lista.Count - 1); j++) | ||
{ | ||
if (dodatni) | ||
{//ulazi u slucaju ako je dodatni zadatak | ||
((Grad)lista[j + 1].Node).izracunajHeuristic(((Grad)endNode).Position); | ||
((Grad)lista[j].Node).izracunajHeuristic(((Grad)endNode).Position); | ||
} | ||
|
||
double temp1 = lista[j + 1].Node.Heuristic + lista[j + 1].Cost; | ||
double temp2 = lista[j].Node.Heuristic + lista[j].Cost; | ||
if (temp1 > temp2) | ||
{ | ||
var temp = lista[j]; | ||
lista[j] = lista[j + 1]; | ||
lista[j + 1] = temp; | ||
flag = true; | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PretrageOsnovno | ||
{ | ||
class BreadthFirstSearch | ||
{ | ||
public State Search(string startNodeName, string endNodeName) | ||
{ | ||
Node startNode = Program.instance.graph[startNodeName]; | ||
Node endNode = Program.instance.graph[endNodeName]; | ||
|
||
List<State> stanjaZaObradu = new List<State>(); | ||
|
||
stanjaZaObradu.Add(new State(startNode)); | ||
|
||
while (stanjaZaObradu.Count > 0) | ||
{ | ||
State naObradi = stanjaZaObradu[0]; | ||
stanjaZaObradu.Remove(naObradi); | ||
|
||
if (naObradi.Node.Name == endNode.Name) | ||
{ | ||
return naObradi; | ||
} | ||
else | ||
{ | ||
List<State> mogucaSledecaStanja = naObradi.children(); | ||
stanjaZaObradu.AddRange(mogucaSledecaStanja); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Collections; | ||
|
||
namespace PretrageOsnovno | ||
{ | ||
class DepthFirstSearch | ||
{ | ||
public State Search(string startNodeName, string endNodeName) | ||
{ | ||
Node startNode = Program.instance.graph[startNodeName]; | ||
Node endNode = Program.instance.graph[endNodeName]; | ||
|
||
List<State> stanjaZaObradu = new List<State>(); | ||
|
||
stanjaZaObradu.Add(new State(startNode)); | ||
|
||
while (stanjaZaObradu.Count > 0) | ||
{ | ||
State naObradi = stanjaZaObradu[0]; | ||
stanjaZaObradu.Remove(naObradi); | ||
|
||
if (naObradi.Node.Name == endNode.Name) | ||
{ | ||
return naObradi; | ||
} | ||
else | ||
{ | ||
List<State> mogucaSledecaStanja = naObradi.children(); | ||
stanjaZaObradu.InsertRange(0, mogucaSledecaStanja); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Windows; | ||
using System.Text; | ||
|
||
namespace PretrageOsnovno | ||
{ | ||
class Grad : Node | ||
{ | ||
|
||
public Grad(string name, Point position):base(name,0) //cena je u pocetku 0 zato sto nzm koji je ciljni grad | ||
{ | ||
this.Position = position; | ||
} | ||
|
||
public Point Position { get; set; } | ||
/// <summary> | ||
/// Na osnovu pozicije grada do kog trebamo stici, racuna heuristiku | ||
/// </summary> | ||
/// <param name="p">Pozicija ciljnog grada</param> | ||
public void izracunajHeuristic(Point p) | ||
{ | ||
var x1 = Position.X; | ||
var y1 = Position.Y; | ||
var x2 = p.X; | ||
var y2 = p.Y; | ||
Console.WriteLine(" " + Math.Pow(5, 2)); | ||
base.Heuristic = (Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2)); | ||
|
||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Windows; | ||
using System.Threading.Tasks; | ||
|
||
namespace PretrageOsnovno | ||
{ | ||
class Graph | ||
{ | ||
public Dictionary<string, Node> graph = null; | ||
|
||
public Graph(string[] linesNodes, string[] linesLinks, bool dodatni) | ||
{ | ||
graph = new Dictionary<string, Node>(); | ||
formGraph(linesNodes, linesLinks,dodatni); | ||
} | ||
|
||
|
||
private void formGraph(string[] linesNodes, string[] linesLinks,bool dodatni) | ||
{ | ||
if (!dodatni) | ||
{//ukoliko nije dodatni | ||
char[] sep = { ':', ',' }; | ||
foreach (String line in linesNodes) | ||
{ | ||
string[] lines = line.Split(sep); | ||
Node node = new Node(lines[0], Double.Parse(lines[1])); | ||
graph.Add(lines[0], node); | ||
|
||
} | ||
} | ||
else | ||
{ | ||
char[] sep = { ':', ',', ')', '(' }; | ||
foreach (String line in linesNodes) | ||
{ | ||
string[] lines = line.Split(sep); | ||
Point p = new Point(Double.Parse(lines[1]), //x i y kordinata | ||
Double.Parse(lines[2])); | ||
|
||
Grad grad = new Grad(lines[0], //naziv | ||
p);//pozicija grada | ||
|
||
graph.Add(lines[0], grad); | ||
|
||
} | ||
|
||
} | ||
|
||
char[] separator = { ':', ',' }; | ||
foreach (String line in linesLinks) | ||
{ | ||
string[] lines = line.Split(separator); | ||
if (graph.ContainsKey(lines[1])) | ||
{ | ||
|
||
Link link = new Link(graph[lines[1]], //startNode | ||
graph[lines[2]], //endNode | ||
lines[0], //name | ||
Double.Parse(lines[3])); //cost | ||
|
||
graph[lines[1]].Links.Add(link); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
} | ||
|
||
#region ispis | ||
public void printGraph() | ||
{ | ||
StringBuilder sb = new StringBuilder(); | ||
foreach (KeyValuePair<string, Node> kvp in graph) | ||
{ | ||
foreach (Link link in kvp.Value.Links) | ||
{ | ||
Console.WriteLine(link.Name + ":" + link.StartNode + "," + link.EndNode + "," + link.Cost); | ||
} | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
put:NS,BG,90 | ||
put:NS,SB,70 | ||
put:SB,UZ,80 | ||
put:BG,UZ,90 | ||
put:BG,KR,110 | ||
put:UZ,KR,40 | ||
put:UZ,NI,190 | ||
put:KR,NI,120 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
NS:250 | ||
BG:190 | ||
SB:210 | ||
UZ:110 | ||
KR:100 | ||
NI:0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
NS(20,15) | ||
BG(55,60) | ||
SB(5,40) | ||
UZ(0,120) | ||
KR(30,150) | ||
NI(55,250) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NS,BG,UZ,KR,NI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Collections; | ||
|
||
namespace PretrageOsnovno | ||
{ | ||
class IterativeDepthFirstSearch | ||
{ | ||
private const int MaxLevel = 10000; | ||
private int currentLevel; | ||
|
||
|
||
public State Search(string startNodeName, string endNodeName) | ||
{ | ||
|
||
Node startNode = Program.instance.graph[startNodeName]; | ||
Node endNode = Program.instance.graph[endNodeName]; | ||
|
||
List<State> stanjaZaObradu = new List<State>(); | ||
|
||
stanjaZaObradu.Add(new State(startNode)); | ||
currentLevel = 1; | ||
while (stanjaZaObradu.Count > 0 && currentLevel < MaxLevel) | ||
{ | ||
State naObradi = stanjaZaObradu[0]; | ||
stanjaZaObradu.Remove(naObradi); | ||
|
||
if (naObradi.Node.Name == endNode.Name) | ||
{ | ||
return naObradi; | ||
} | ||
else | ||
{ | ||
if (naObradi.Level < currentLevel) | ||
{ | ||
List<State> mogucaSledecaStanja = naObradi.children(); | ||
stanjaZaObradu.InsertRange(0, mogucaSledecaStanja); | ||
} | ||
else | ||
{ | ||
if (stanjaZaObradu.Count == 0) | ||
{ | ||
currentLevel++; | ||
stanjaZaObradu.Add(new State(startNode)); | ||
} | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sortiranje je "skupa" operacija. Teorijski je tacno ovo sto si ti uradio, ali je sa stanovista implementacije bolje pronaci minimalni element i njega poslati na obradu.