[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: incompatible types in assignment
From: |
glen e. p. ropella |
Subject: |
Re: incompatible types in assignment |
Date: |
Wed, 29 Jan 1997 09:15:32 -0700 |
> I create a collection of actionGroups for schedule agents
> which they move with different speed. An actionGroup in the
> collection gathers agents which they move with the same speed.
> So at each timestep I activate the actionGroup which give
> the result getCurrentTime()%agentSpeed == 0.
>
> Bruno
It sounds like what you want to do is create a bunch
of schedules, each with different repeat intervals.
This might look like the following:
------------------------------------------------------------------
id <Schedule> schedule[10];
id <List> agentlist[10];
int agentSpeed[10];
for(i=0;i<10;i++) {
schedule[i] = [Schedule createBegin: [self getZone]];
[schedule[i] setRepeatInterval: agentSpeed[i]];
schedule[i] = [schedule[i] createEnd];
[schedule[i] at: 0 createActionForEach: agentList[i] message: M(step)];
}
[...later...]
for(i=0;i<10;i++)
[schedule[i] activateIn: self] // where self is a swarm
---------------------------------------------------------------------
Or, perhaps you could do it this way:
---------------------------------------------------------------------
id <Schedule> schedule;
id <List> agentList[10];
int agentSpeed[10], sortedAgentSpeed[10], sortMap[10];
int maxAgentSpeed;
schedule = [Schedule createBegin: [self getZone]];
[schedule setRepeatInterval: 1];
schedule = [schedule createEnd];
sortedAgentSpeed = sort(agentSpeed, sortMap);
for (i=0; i<10; i++) {
j = sortedAgentSpeed[i];
while (j <= maxAgentSpeed) {
[schedule at: j createActionForEach: agentList[sortMap[i]]
message: M(step)];
j += mod( sortedAgentSpeed[i],maxAgentSpeed)
}
}
-------------------------------------------------------------------
which, if I'm rippingly lucky [grin], will create a single
schedule that sends the message "step" to all the agents on each
list according to their frequency.
Say, if I have 5 agent speeds, each with 10 agents:
agentSpeed[0] = 7;
agentSpeed[1] = 2;
agentSpeed[2] = 10;
agentSpeed[3] = 3;
agentSpeed[4] = 5;
Then maxAgentSpeed = 10; sortedAgentSpeed = {2,3,5,7,10};
sortMap = {1,3,4,0,2}; And the sequences of j's will be
i = 0; j = 2, 4, 6, 8, 10;
i = 1; j = 3, 6, 9;
i = 2; j = 5, 10;
i = 3; j = 7;
i = 4; j = 10;
Hopefully, this will create a schedule that looks like this:
t = 0 => nothing to do
t = 1 => nothing to do
t = 2 => do agentList[1]
t = 3 => do agentList[3]
t = 4 => do agentList[1]
t = 5 => do agentList[4]
t = 6 => do agentList[1] & agentList[3]
t = 7 => do agentList[0]
t = 8 => do agentList[1]
t = 9 => do agentList[3]
t = 10 => do agentList[1] & agentList[4] & agentList[2]
Repeat.
There could be a problem with time 0 and there could be a problem
with the sizes (using 10 and the maxAgentSpeed being equal to 10,
etc.) But, overall, I don't think this is a bad idea. Of course,
the first option is easier!
glen