Skip to content
Snippets Groups Projects
Commit b5bcd41a authored by Alexandre's avatar Alexandre
Browse files

Fix poll new data condition

parent 430962bf
No related branches found
No related tags found
No related merge requests found
...@@ -27,15 +27,16 @@ public class DynamicClusteringAMAS<T extends DataPoint> extends Amas<DynamicClus ...@@ -27,15 +27,16 @@ public class DynamicClusteringAMAS<T extends DataPoint> extends Amas<DynamicClus
protected void onSystemCycleBegin() { protected void onSystemCycleBegin() {
if (logger.isLoggable(Level.INFO)) if (logger.isLoggable(Level.INFO))
logger.info("---- BEGIN MAS CYCLE ----"); logger.info("---- BEGIN MAS CYCLE ----");
if (agents.isEmpty() || allAgentsAreDormant()) { if (agents.isEmpty() || allAgentsAreReadyToStop()) {
var newDataPoint = environment.pollPendingDataPoint(); var newDataPoint = environment.pollPendingDataPoint();
newDataPoint.ifPresent(dataPoint -> new DataPointAgent<T>(this, dataPoint)); newDataPoint.ifPresent(dataPoint -> new DataPointAgent<T>(this, dataPoint));
} }
} }
private boolean allAgentsAreDormant() { private boolean allAgentsAreReadyToStop() {
return agents.stream() return agents.stream()
.noneMatch(agent -> agent instanceof ClusterAgent clusterAgent && !clusterAgent.readyToStop()); .noneMatch(agent -> (agent instanceof ClusterAgent clusterAgent && !clusterAgent.readyToStop()) ||
(agent instanceof DataPointAgent dataPointAgent && !dataPointAgent.readyToStop()));
} }
@Override @Override
...@@ -49,7 +50,6 @@ public class DynamicClusteringAMAS<T extends DataPoint> extends Amas<DynamicClus ...@@ -49,7 +50,6 @@ public class DynamicClusteringAMAS<T extends DataPoint> extends Amas<DynamicClus
@Override @Override
public boolean stopCondition() { public boolean stopCondition() {
return !environment.hasRemainingPendingAdditionDataPoints() && return !environment.hasRemainingPendingAdditionDataPoints() &&
agents.stream().noneMatch(agent -> agent instanceof ClusterAgent clusterAgent && !clusterAgent.readyToStop()) && allAgentsAreReadyToStop();
agents.stream().noneMatch(agent -> agent instanceof DataPointAgent);
} }
} }
...@@ -142,6 +142,10 @@ public class DataPointAgent<T extends DataPoint> extends Agent<DynamicClustering ...@@ -142,6 +142,10 @@ public class DataPointAgent<T extends DataPoint> extends Agent<DynamicClustering
} }
} }
public boolean readyToStop() {
return false;
}
private record ClusterSimilarityScore<T extends DataPoint>(Cluster<T> cluster, float score) { private record ClusterSimilarityScore<T extends DataPoint>(Cluster<T> cluster, float score) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment