I am using Repast Simphony framework for simulation. Let's say that I have following class:
public class Generator {
private String name;
private Random random;
public Generator(String name) {
this.name = name;
this.random = new Random();
}
public double getValue() {
return random.nextDouble();
}
}
Then I create several instances of this class, add them to context and run simulation:
public class Builder implements ContextBuilder<Object> {
@Override
public Context build(Context<Object> context) {
context.add(new Generator("Gen1"));
context.add(new Generator("Gen2"));
context.add(new Generator("Gen3"));
return context;
}
}
Is there any way to collect aggregated data, but for each instance of class separately? I would like to find out mean of all generated values for each generator, so output statistics should be in following format:
Name,Mean
Gen1,0.458
Gen2,0.512
Gen3,0.463
If I create new aggregated (mean) Data Set with Method Data Source Generator.getValue
and repeat each tick, I get large list of values:
Tick,Mean
1,0.365
2,0.456
3,0.728
4,0.091
...
where each value is mean, but mean of values in specified tick from all generators, not mean of values in all ticks from one generator. Is there any way to do this using Repast Simphony?
EDIT: When I want to use Custom Data Sources, add class Generator implements AggregateDataSource
and add methods:
@Override
public String getId() {
return name;
}
@Override
public Class<?> getDataType() {
return Double.class;
}
@Override
public Class<?> getSourceType() {
return Generator.class;
}
@Override
public Object get(Iterable<?> objs, int size) {
return 7.0; // Not mean, only mock value for testing.
}
@Override
public void reset() {
// TODO Auto-generated method stub
}
error appears: