Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ class ImageFitness(alias toShape, alias rasterizer, size_t genomSize)

void gaCircle(in Options options, Tid someId)
{
auto fitness = new ImageFitness!(toCircle, rasterizeCircles, circleGenomSize)(options.input, someId);
geneticAlgorithm!fitness(circleGenomSize * options.shapeCount, 0.0, 50, options.mutation, options.maxEpoch,
options.forever);
auto fitness = new ImageFitness!(toCircle, rasterizeCircles, circleGenomSize)(options.input, someId);
geneticAlgorithm!fitness(circleGenomSize * options.shapeCount, 0.0, 50, options.mutation, options.maxEpoch,
options.forever);
send(ownerTid, true);
}

void gaRectangle(in Options options, Tid someId)
Expand All @@ -97,6 +98,7 @@ void gaRectangle(in Options options, Tid someId)
someId);
geneticAlgorithm!fitness(rectangleGenomSize * options.shapeCount, 0.0, 50, options.mutation, options.maxEpoch,
options.forever);
send(ownerTid, true);
}

void drawingThread(in Options options)
Expand All @@ -120,6 +122,7 @@ void drawingThread(in Options options)
"Genetický algoritmus"
);

bool stop = false;
while (window.isOpen())
{
Event event;
Expand All @@ -133,7 +136,16 @@ void drawingThread(in Options options)
receiveTimeout(100.msecs, (shared SfmlImage img)
{
loadImageIntoSprite(cast(SfmlImage) img, sprite);
},
(bool _)
{
stop = true;
});
if(stop)
{
window.close();
break;
}
window.clear(Color.White);
if(sprite !is null) window.draw(sprite);
window.display();
Expand Down
2 changes: 1 addition & 1 deletion source/genetic.d
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Individual!fitness geneticAlgorithm(alias fitness)(size_t genomSize, double requ
}
generationNumber += 1;
if(generationNumber >= generationMax && !infinite) break;
receiveTimeout(1.msecs, (OwnerTerminated own) { running = false; });
receiveTimeout(-1.msecs, (OwnerTerminated own) { running = false; });
}
return current.getFittest();
}