-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preparations for integration test of MiniZinc Intelligent Ensembles.
Moved DummyEnsembleTest into its own package.
- Loading branch information
Showing
13 changed files
with
204 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
4 changes: 3 additions & 1 deletion
4
.../demo/intelligent/DummyEnsemblesTest.java → ...co/demo/ensembles/DummyEnsemblesTest.java
This file contains 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
5 changes: 2 additions & 3 deletions
5
...mff/d3s/deeco/demo/intelligent/Robot.java → ...i/mff/d3s/deeco/demo/ensembles/Robot.java
This file contains 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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
package cz.cuni.mff.d3s.deeco.demo.intelligent; | ||
package cz.cuni.mff.d3s.deeco.demo.ensembles; | ||
|
||
import cz.cuni.mff.d3s.deeco.annotations.Component; | ||
|
||
@Component | ||
public class Robot { | ||
public String id; | ||
|
||
|
||
public Robot(String name) { | ||
this.id = name; | ||
} | ||
|
||
public String getName() { | ||
return id; | ||
return id; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...eeco/demo/intelligent/SimpleEnsemble.java → .../deeco/demo/ensembles/SimpleEnsemble.java
This file contains 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
2 changes: 1 addition & 1 deletion
2
...mo/intelligent/SimpleEnsembleFactory.java → ...demo/ensembles/SimpleEnsembleFactory.java
This file contains 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
26 changes: 26 additions & 0 deletions
26
jdeeco-core/test/cz/cuni/mff/d3s/deeco/demo/intelligent/IntelligentEnsemble.java
This file contains 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,26 @@ | ||
package cz.cuni.mff.d3s.deeco.demo.intelligent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import cz.cuni.mff.d3s.deeco.ensembles.EnsembleInstance; | ||
|
||
public class IntelligentEnsemble implements EnsembleInstance { | ||
|
||
public int trainId; | ||
|
||
public IntelligentEnsemble(int trainId) { | ||
this.trainId = trainId; | ||
members = new ArrayList<>(); | ||
} | ||
|
||
public List<Rescuer> members; | ||
|
||
@Override | ||
public void performKnowledgeExchange() { | ||
for (Rescuer member : members) { | ||
member.trainId = trainId; | ||
} | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
jdeeco-core/test/cz/cuni/mff/d3s/deeco/demo/intelligent/IntelligentEnsemble.mzn
This file contains 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,31 @@ | ||
% Two pendolinos crash, one at kilometer 50, one at kilometer 25. | ||
% Both accidents are equally severe. | ||
% | ||
% We have rescuers located along the track. The task is to send | ||
% half of the rescuer components to one crash and the other half | ||
% to the other accident, while minimizing the summed distance | ||
% of all rescuers to their site. | ||
|
||
% the component_count must be divisible by train_count!!! | ||
|
||
int: component_count; | ||
int: train_count; | ||
|
||
set of int: COMPONENTS = 1..component_count; | ||
set of int: TRAINS = 1..train_count; | ||
|
||
array[COMPONENTS] of int: component_pos; | ||
array[TRAINS] of int: train_pos; | ||
|
||
array[COMPONENTS] of var TRAINS: component_train; | ||
array[COMPONENTS] of var int: component_distance; | ||
var int: distance_sum_sqr; | ||
|
||
% teams have equal size | ||
constraint forall(t in TRAINS)(sum(c in COMPONENTS)(if component_train[c] = t then 1 else 0 endif) = component_count div train_count); | ||
|
||
% distance | ||
constraint forall(c in COMPONENTS)(component_distance[c] = abs(component_pos[c] - train_pos[component_train[c]])); | ||
constraint distance_sum_sqr = sum(c in COMPONENTS)(component_distance[c] * component_distance[c]); | ||
|
||
solve minimize distance_sum_sqr; |
76 changes: 76 additions & 0 deletions
76
jdeeco-core/test/cz/cuni/mff/d3s/deeco/demo/intelligent/IntelligentEnsembleFactory.java
This file contains 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,76 @@ | ||
package cz.cuni.mff.d3s.deeco.demo.intelligent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import cz.cuni.mff.d3s.deeco.ensembles.EnsembleFormationException; | ||
import cz.cuni.mff.d3s.deeco.ensembles.EnsembleInstance; | ||
import cz.cuni.mff.d3s.deeco.ensembles.intelligent.MiniZincIntelligentEnsembleFactory; | ||
import cz.cuni.mff.d3s.deeco.ensembles.intelligent.MznScriptRunner; | ||
import cz.cuni.mff.d3s.deeco.ensembles.intelligent.OutputVariableParseException; | ||
import cz.cuni.mff.d3s.deeco.ensembles.intelligent.ScriptInputVariableRegistry; | ||
import cz.cuni.mff.d3s.deeco.ensembles.intelligent.ScriptOutputVariableRegistry; | ||
import cz.cuni.mff.d3s.deeco.ensembles.intelligent.UnsupportedVariableTypeException; | ||
import cz.cuni.mff.d3s.deeco.knowledge.container.KnowledgeContainer; | ||
import cz.cuni.mff.d3s.deeco.knowledge.container.KnowledgeContainerException; | ||
|
||
public class IntelligentEnsembleFactory extends MiniZincIntelligentEnsembleFactory { | ||
|
||
private List<Rescuer> rescuers; | ||
private static final Integer[] trainPositions = {50, 25}; | ||
|
||
public IntelligentEnsembleFactory() { | ||
super("cz/cuni/mff/d3s/deeco/demo/intelligent/IntelligentEnsemble.mzn"); | ||
} | ||
|
||
@Override | ||
public int getSchedulingOffset() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getSchedulingPeriod() { | ||
return 1000; | ||
} | ||
|
||
@Override | ||
protected ScriptInputVariableRegistry parseInput(KnowledgeContainer knowledgeContainer) throws EnsembleFormationException { | ||
try { | ||
ScriptInputVariableRegistry result = new ScriptInputVariableRegistry(); | ||
rescuers = new ArrayList<>(knowledgeContainer.getTrackedKnowledgeForRole(Rescuer.class)); | ||
result.addVariable("component_count", rescuers.size()); | ||
result.addVariable("train_count", trainPositions.length); | ||
result.addVariable("component_pos", rescuers.stream().map(r -> r.pos).collect(Collectors.toList()).toArray()); | ||
result.addVariable("train_pos", trainPositions); | ||
return result; | ||
|
||
} catch (UnsupportedVariableTypeException | KnowledgeContainerException e) { | ||
throw new EnsembleFormationException(e); | ||
} | ||
} | ||
|
||
@Override | ||
protected Collection<EnsembleInstance> createInstancesFromOutput(ScriptOutputVariableRegistry scriptOutput) throws EnsembleFormationException { | ||
try { | ||
Integer[] componentPlacement = scriptOutput.getArray1dValue("component_train", Integer.class); | ||
|
||
List<EnsembleInstance> result = new ArrayList<>(); | ||
for (int i = 1; i <= trainPositions.length; i++) { | ||
IntelligentEnsemble ensemble = new IntelligentEnsemble(i); | ||
result.add(ensemble); | ||
} | ||
|
||
for (int j = 0; j < componentPlacement.length; j++) { | ||
((IntelligentEnsemble) result.get(componentPlacement[j])).members.add(rescuers.get(j)); | ||
} | ||
|
||
return result; | ||
|
||
} catch (UnsupportedVariableTypeException | OutputVariableParseException e) { | ||
throw new EnsembleFormationException(e); | ||
} | ||
} | ||
|
||
} |
This file contains 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
12 changes: 12 additions & 0 deletions
12
jdeeco-core/test/cz/cuni/mff/d3s/deeco/demo/intelligent/Rescuer.java
This file contains 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,12 @@ | ||
package cz.cuni.mff.d3s.deeco.demo.intelligent; | ||
|
||
import cz.cuni.mff.d3s.deeco.annotations.Role; | ||
|
||
@Role | ||
public class Rescuer { | ||
|
||
public Integer pos; | ||
|
||
public Integer trainId; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
jdeeco-core/test/cz/cuni/mff/d3s/deeco/demo/intelligent/RescuerComponent.java
This file contains 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,21 @@ | ||
package cz.cuni.mff.d3s.deeco.demo.intelligent; | ||
|
||
import cz.cuni.mff.d3s.deeco.annotations.Component; | ||
import cz.cuni.mff.d3s.deeco.annotations.PlaysRole; | ||
|
||
@Component | ||
@PlaysRole(Rescuer.class) | ||
public class RescuerComponent { | ||
|
||
public String id; | ||
|
||
public Integer pos; | ||
|
||
public Integer trainId; | ||
|
||
public RescuerComponent(String id, Integer pos) { | ||
this.id = id; | ||
this.pos = pos; | ||
} | ||
|
||
} |