Displaying histograms while creating agents

43 views
Skip to first unread message

mathieu....@gmail.com

unread,
Mar 12, 2019, 6:15:29 AM3/12/19
to GAMA
Hello everyone,

I am currently having troubles with displaying histograms and actually, I don't if what I try to is possible or not.
As shows the example code, I want to display histograms representing an information related to an agnt testA, stored in an agent testB. In the example code, the right information is displayed. However, it does not take into account the new agents testA created during the simulation.

Any advice is welcome.

Thank You

Mathieu

testDisplays.gaml

Benoit Gaudou

unread,
Mar 13, 2019, 11:34:18 PM3/13/19
to gama-p...@googlegroups.com
Hi Mathieu,

I just had a look at a part of your issue: the fact to take into account new agents.
You could have a look at the datalist statement instead of the data (see below)

display "d"{

chart "information" type:series //histogram

// style:stack

{

datalist legend: testA accumulate each.name 

value: testA accumulate 2;


}

} 


Now you need to compute the value you want for each element ?

Cheers

Benoit



--
You received this message because you are subscribed to the Google Groups "GAMA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gama-platfor...@googlegroups.com.
To post to this group, send email to gama-p...@googlegroups.com.
Visit this group at https://groups.google.com/group/gama-platform.
For more options, visit https://groups.google.com/d/optout.

mathieu....@gmail.com

unread,
Mar 14, 2019, 5:50:33 AM3/14/19
to GAMA
Hi Benoit,

This is not exactly what I am trying to do. I want to plot the information contained in each agent testB, an information related to testA agents.
Your solution enables to take into account the new tesA agents but it does not plot the information for each testB agent.
I have try something like this :

loop tempA over:testA{
datalist legend: testA accumulate each.name value: testB collect each.myA[tempA] ;
}

But it does not work at all.

The example code i gave previously is working well with the testA agents created at the begining (and adding testB agents works well also). The problem is whith the addition of testA agents which are not taken into account on the chart.

Cheers

Mathieu

Benoit Gaudou

unread,
Mar 14, 2019, 11:52:25 PM3/14/19
to gama-p...@googlegroups.com
Hi,

I defined the list to display in the global... seems to work: 

model testDisplays


global{ list<string> lname;

list<int> lvalue;

list<rgb> lCol;

init{

create testA number:5;

create testB number:2;

}

reflex update {


loop tempA over:testA{

add tempA.name to: lname;

add sum(testB collect each.myA[tempA]) to: lvalue;

add tempA.color to: lCol; 

// data tempA.name style: stack value:(testB collect each.myA[tempA]) color: tempA.color;

}

}

reflex creation{

create testA number:1;

}

}


species testA{

int a;

rgb color <- rgb(rnd(255),rnd(255),rnd(255));

init{

a <- rnd(10);

}

}


species testB{

map<testA,int> myA;

init{

loop temp over:testA{

add temp::temp.a to: myA;

}

}

reflex doSomething{

testA tempA <- one_of(testA);

put tempA.a at:tempA in: myA;

}

}


experiment testExpe type: gui {

output {

display "information"{

chart "information" type: histogram

style:stack

{

datalist lname value: lvalue color: lCol;

// datalist tempA collect(each.name) value: testA collect(each) color: tempA collect(each.color);

}

}  

}

}

mathieu....@gmail.com

unread,
Mar 15, 2019, 6:29:29 AM3/15/19
to gama-p...@googlegroups.com
Hi,

Your solution does not do quite what I what but it gave me ideas and I found the solution. I put the working code here so if anyone as the same problem, here my solution.

Thanks a lot

Mathieu

testDisplays.gaml
Reply all
Reply to author
Forward
0 new messages