best first
This commit is contained in:
parent
ef2ef838a2
commit
11c1c934fc
@ -130,19 +130,19 @@ namespace MonoGameView.Algorithms
|
|||||||
//Thread.Sleep(1);
|
//Thread.Sleep(1);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
var nodes = new List<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>() {
|
var nodes = new Queue<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
|
||||||
new Tuple<List<IStep>, GarbageCollector, ICloneable[,]>(new List<IStep>(),collector,grid)
|
nodes.Enqueue(new Tuple<List<IStep>, GarbageCollector, ICloneable[,]>(new List<IStep>(), collector, grid));
|
||||||
};
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
|
||||||
Console.WriteLine(count);
|
Console.WriteLine(count);
|
||||||
Console.WriteLine(nodes.Count);
|
Console.WriteLine(nodes.Count);
|
||||||
count++;
|
count++;
|
||||||
var nodes2 = new List<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
|
//var nodes2 = new List<Tuple<List<IStep>, GarbageCollector, ICloneable[,]>>();
|
||||||
foreach (var item in nodes)
|
while (true)
|
||||||
{
|
{
|
||||||
//Thread.Sleep(1);
|
var item = nodes.Dequeue();
|
||||||
|
Thread.Sleep(10);
|
||||||
this.Collector.Coords = item.Item2.Coords;
|
this.Collector.Coords = item.Item2.Coords;
|
||||||
this.Collector.TrashContainers = item.Item2.TrashContainers;
|
this.Collector.TrashContainers = item.Item2.TrashContainers;
|
||||||
for (int x = 0; x < item.Item3.GetLength(0); x++)
|
for (int x = 0; x < item.Item3.GetLength(0); x++)
|
||||||
@ -174,13 +174,12 @@ namespace MonoGameView.Algorithms
|
|||||||
var steps = new List<IStep>();
|
var steps = new List<IStep>();
|
||||||
steps.AddRange(item.Item1);
|
steps.AddRange(item.Item1);
|
||||||
steps.Add(step);
|
steps.Add(step);
|
||||||
nodes2.Add(new Tuple<List<IStep>, GarbageCollector, ICloneable[,]>(steps, collectorClone, gridClone));
|
nodes.Enqueue(new Tuple<List<IStep>, GarbageCollector, ICloneable[,]>(steps, collectorClone, gridClone));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
nodes = nodes2;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ namespace CzokoŚmieciarka.MonoGameView.Algorithms
|
|||||||
KeyValuePair<List<IStep>, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
|
KeyValuePair<List<IStep>, int> Search(ContentManager content, GarbageCollector collector, ICloneable[,] grid, int length)
|
||||||
{
|
{
|
||||||
|
|
||||||
//Thread.Sleep(10);
|
Thread.Sleep(10);
|
||||||
this.Collector.Coords = collector.Coords;
|
this.Collector.Coords = collector.Coords;
|
||||||
this.Collector.TrashContainers = collector.TrashContainers;
|
this.Collector.TrashContainers = collector.TrashContainers;
|
||||||
|
|
||||||
|
@ -34,6 +34,15 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans
|
|||||||
{
|
{
|
||||||
//if (this.TypeOfGarbage.GarbageType != garbage.TypeOfGarbage.GarbageType)
|
//if (this.TypeOfGarbage.GarbageType != garbage.TypeOfGarbage.GarbageType)
|
||||||
// throw new Exception("You cannot add up different type garbage!");
|
// throw new Exception("You cannot add up different type garbage!");
|
||||||
|
if (FillPercent == 1) return false;
|
||||||
|
|
||||||
|
if (this.Garbage.Volume + garbage.Volume > this.MaxVolume)
|
||||||
|
{
|
||||||
|
this.Garbage.Weight = this.MaxVolume;
|
||||||
|
garbage.Weight = (this.MaxVolume - this.Garbage.Volume);
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
|
||||||
var newGarbage = this.Garbage + garbage;
|
var newGarbage = this.Garbage + garbage;
|
||||||
if (newGarbage.Volume > this.MaxVolume)
|
if (newGarbage.Volume > this.MaxVolume)
|
||||||
@ -42,20 +51,35 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Interfaces.TrashCans
|
|||||||
this.Garbage = newGarbage;
|
this.Garbage = newGarbage;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public virtual object Clone()
|
public virtual object Clone()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual AGarbage TakeGarbage()
|
public virtual AGarbage TakeGarbage(double maxVolume)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (this.Garbage.Weight == 0)
|
if (this.Garbage.Weight == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
if (this.Garbage.Volume > maxVolume)
|
||||||
|
{
|
||||||
|
var result = (AGarbage)this.Garbage.Clone();
|
||||||
|
result.Weight = maxVolume;
|
||||||
|
this.Garbage.Weight = this.Garbage.Weight - maxVolume;
|
||||||
|
return result;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
|
||||||
var result = (AGarbage)this.Garbage.Clone();
|
var result = (AGarbage)this.Garbage.Clone();
|
||||||
this.Garbage.Weight = 0;
|
this.Garbage.Weight = 0;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,10 +68,8 @@ namespace MonoGameView.DataModels
|
|||||||
type = GarbageType.PlasticMetal;
|
type = GarbageType.PlasticMetal;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
int canDensity = Convert.ToInt32(trashCanNode.SelectSingleNode("Density").InnerText);
|
|
||||||
int canProcessingTimePerUnit = Convert.ToInt32(trashCanNode.SelectSingleNode("ProcessingTimePerUnit").InnerText);
|
|
||||||
int volume = Convert.ToInt32(trashCanNode.SelectSingleNode("Volume").InnerText);
|
int volume = Convert.ToInt32(trashCanNode.SelectSingleNode("Volume").InnerText);
|
||||||
TypeOfGarbage canTypeOfGarbage = new TypeOfGarbage(type, canDensity,canProcessingTimePerUnit);
|
TypeOfGarbage canTypeOfGarbage = new TypeOfGarbage(type, 1,0);
|
||||||
TrashCan trashCan = new TrashCan(canTypeOfGarbage, volume, new BasicGarbage(canTypeOfGarbage, volume));
|
TrashCan trashCan = new TrashCan(canTypeOfGarbage, volume, new BasicGarbage(canTypeOfGarbage, volume));
|
||||||
trashCans.Add(trashCan);
|
trashCans.Add(trashCan);
|
||||||
}
|
}
|
||||||
@ -101,10 +99,7 @@ namespace MonoGameView.DataModels
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int density = Convert.ToInt32(garbageNode.SelectSingleNode("Density").InnerText);
|
typeOfGarbage = new TypeOfGarbage(garbageType, 1,0);
|
||||||
int processingTimePerUnit = Convert.ToInt32(garbageNode.SelectSingleNode("ProcessingTimePerUnit").InnerText);
|
|
||||||
int maxVolume = Convert.ToInt32(objectNode.SelectSingleNode("Volume").InnerText);
|
|
||||||
typeOfGarbage = new TypeOfGarbage(garbageType, density, processingTimePerUnit);
|
|
||||||
Dump dump = new Dump(typeOfGarbage, int.MaxValue, new Coords(x, y));
|
Dump dump = new Dump(typeOfGarbage, int.MaxValue, new Coords(x, y));
|
||||||
grid[x, y] = dump;
|
grid[x, y] = dump;
|
||||||
break;
|
break;
|
||||||
|
@ -29,7 +29,12 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps
|
|||||||
|
|
||||||
var trashCans = _garbageLocalization.TrashCans.Where(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage);
|
var trashCans = _garbageLocalization.TrashCans.Where(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage);
|
||||||
if (!trashCans.Any()) return false;
|
if (!trashCans.Any()) return false;
|
||||||
var preGarbage = trashCans.Select(t => t.TakeGarbage()).ToList();
|
var mainCan = _garbageCollector
|
||||||
|
.TrashContainers
|
||||||
|
.Where(x => x.TypeOfGarbage.GarbageType == _typeOfGarbage)
|
||||||
|
.First();
|
||||||
|
var maxVolume = mainCan.MaxVolume - mainCan.Garbage.Weight;
|
||||||
|
var preGarbage = trashCans.Select(t => t.TakeGarbage(maxVolume)).ToList();
|
||||||
if (preGarbage.Any(x => x == null)) return false;
|
if (preGarbage.Any(x => x == null)) return false;
|
||||||
var garbage = preGarbage.Aggregate((a,b)=>a+b);
|
var garbage = preGarbage.Aggregate((a,b)=>a+b);
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@ namespace CzokoŚmieciarka.MonoGameView.DataModels.Models.Steps
|
|||||||
var containers = _garbageCollector.TrashContainers.Where(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage && t.FillPercent > 0);
|
var containers = _garbageCollector.TrashContainers.Where(t => t.TypeOfGarbage.GarbageType == _typeOfGarbage && t.FillPercent > 0);
|
||||||
if (containers.Any())
|
if (containers.Any())
|
||||||
{
|
{
|
||||||
var preGarbage = containers.Select(t => t.TakeGarbage()).ToList();
|
|
||||||
|
var preGarbage = containers.Select(t => t.TakeGarbage(double.MaxValue)).ToList();
|
||||||
if (preGarbage.Any(x => x == null)) return false;
|
if (preGarbage.Any(x => x == null)) return false;
|
||||||
var garbage = preGarbage.Aggregate((a, b) => a + b);
|
var garbage = preGarbage.Aggregate((a, b) => a + b);
|
||||||
if (!_dump.AddGarbage(garbage)) return false;
|
if (!_dump.AddGarbage(garbage)) return false;
|
||||||
|
@ -64,12 +64,12 @@ namespace CzokoŚmieciarka.MonoGameView
|
|||||||
// TODO: Add your initialization logic here
|
// TODO: Add your initialization logic here
|
||||||
timer = 0f;
|
timer = 0f;
|
||||||
|
|
||||||
mapLoader.Load(out size,out grid,"map3.xml");
|
mapLoader.Load(out size,out grid,"map1.xml");
|
||||||
var containers = new List<GarbageCollectorContainer>()
|
var containers = new List<GarbageCollectorContainer>()
|
||||||
{
|
{
|
||||||
new GarbageCollectorContainer(
|
new GarbageCollectorContainer(
|
||||||
new TypeOfGarbage(GarbageType.Glass,1),
|
new TypeOfGarbage(GarbageType.Glass,1),
|
||||||
10000,
|
50,
|
||||||
new BasicGarbage(new TypeOfGarbage(GarbageType.Glass,1),0)
|
new BasicGarbage(new TypeOfGarbage(GarbageType.Glass,1),0)
|
||||||
),
|
),
|
||||||
new GarbageCollectorContainer(
|
new GarbageCollectorContainer(
|
||||||
@ -93,7 +93,7 @@ namespace CzokoŚmieciarka.MonoGameView
|
|||||||
|
|
||||||
|
|
||||||
stepN = 0;
|
stepN = 0;
|
||||||
var dfs = new DFS(collector,grid);
|
var dfs = new BestFirstSearch(collector,grid);
|
||||||
//steps = dfs.BestPath(Content, collector, grid);
|
//steps = dfs.BestPath(Content, collector, grid);
|
||||||
new Thread(delegate() {
|
new Thread(delegate() {
|
||||||
var x = dfs.BestPath(Content, collector, grid);
|
var x = dfs.BestPath(Content, collector, grid);
|
||||||
|
@ -45,8 +45,10 @@
|
|||||||
<StartupObject />
|
<StartupObject />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Algorithms\BestFirstSearch.cs" />
|
||||||
<Compile Include="Algorithms\BFS.cs" />
|
<Compile Include="Algorithms\BFS.cs" />
|
||||||
<Compile Include="Algorithms\DFS.cs" />
|
<Compile Include="Algorithms\DFS.cs" />
|
||||||
|
<Compile Include="Algorithms\PriorityQueue.cs" />
|
||||||
<Compile Include="DataModels\Displayer.cs" />
|
<Compile Include="DataModels\Displayer.cs" />
|
||||||
<Compile Include="DataModels\Enums\Directions.cs" />
|
<Compile Include="DataModels\Enums\Directions.cs" />
|
||||||
<Compile Include="DataModels\Enums\GarbageTypes.cs" />
|
<Compile Include="DataModels\Enums\GarbageTypes.cs" />
|
||||||
|
Loading…
Reference in New Issue
Block a user