This site requires JavaScript, please enable it in your browser!
Greenfoot back
Jemy
Jemy wrote ...

2021/5/10

How to generate the entire timing of the simulation

1
2
Jemy Jemy

2021/5/10

#
I need help on how i will determine the entire time it takes my simulation to run
danpost danpost

2021/5/10

#
Jemy wrote...
I need help on how i will determine the entire time it takes my simulation to run
Do you want real time or number of acts? What kind of sim is it?
Jemy Jemy

2021/5/10

#
danpost wrote...
Jemy wrote...
I need help on how i will determine the entire time it takes my simulation to run
Do you want real time or number of acts? What kind of sim is it?
real time.. Event-driven Sim
Jemy Jemy

2021/5/10

#
I initialized a timer variable in my world fields and increment it in worlds act method. my challenge is how to tell the time to stop after the whole simulation run completes.
danpost danpost

2021/5/10

#
Jemy wrote...
I initialized a timer variable in my world fields and increment it in worlds act method. my challenge is how to tell the time to stop after the whole simulation run completes.
If you want to put a condition on when the timer runs, then do it.
Jemy Jemy

2021/5/10

#
danpost wrote...
Jemy wrote...
I initialized a timer variable in my world fields and increment it in worlds act method. my challenge is how to tell the time to stop after the whole simulation run completes.
If you want to put a condition on when the timer runs, then do it.
I have put this code but it's not stopping the simulation
 private void stopSimulation(){
        if(grant_voteCount == world.NUMBER_OF_SERVER)
        { 
            Greenfoot.stop();
        }
    }
danpost danpost

2021/5/11

#
If this is for your FOLLOWER, CANDIDATE, LEADER scenario? If so, my thought was that using reset between runs is not the proper way to construct your project. Using the 'Run' button is fine, however. Then again, keeping the scenario running and using key or mouse input to begin a subsequent run would be even better. The simple way to know the difference between running and done is the content of lowServer (if "null", running; otherwise, done). This comparison along should allow you to remove the done field. This comparison can also be used in the world's started method to determine if a resetting of field values is in order.
Jemy Jemy

2021/5/11

#
danpost wrote...
If this is for your FOLLOWER, CANDIDATE, LEADER scenario? If so, my thought was that using reset between runs is not the proper way to construct your project. Using the 'Run' button is fine, however. Then again, keeping the scenario running and using key or mouse input to begin a subsequent run would be even better. The simple way to know the difference between running and done is the content of lowServer (if "null", running; otherwise, done). This comparison along should allow you to remove the done field. This comparison can also be used in the world's started method to determine if a resetting of field values is in order.
I use reset to reset the world and used run to run the simulation again. any clue on how to code the running aspect will be appreciated. Thank you
danpost danpost

2021/5/11

#
Jemy wrote...
any clue on how to code the running aspect will be appreciated. Thank you
Big clue just given:
danpost wrote...
This comparison can also be used in the world's started method to determine if a resetting of field values is in order.
The started method of the currently active world will automatically be called by greenfoot when the scenario goes into a running state.
Jemy Jemy

2021/5/13

#
danpost wrote...
Jemy wrote...
any clue on how to code the running aspect will be appreciated. Thank you
Big clue just given:
danpost wrote...
This comparison can also be used in the world's started method to determine if a resetting of field values is in order.
The started method of the currently active world will automatically be called by greenfoot when the scenario goes into a running state.
I wrote a nextRun method that is taking of this. Thanks again
Jemy Jemy

2021/5/13

#
I am thinking of selecting a percentage of the servers that will assumed a failed state. I have not been able to think through on how to write the code to select lets say 2 from the whole servers. eg. if you select 0% as failed all server runs but if you select 10% then 10% of server will assume a failed state and will not participate in the simulation etc.
danpost danpost

2021/5/13

#
Jemy wrote...
I am thinking of selecting a percentage of the servers that will assumed a failed state. I have not been able to think through on how to write the code to select lets say 2 from the whole servers. eg. if you select 0% as failed all server runs but if you select 10% then 10% of server will assume a failed state and will not participate in the simulation etc.
Maybe your world could use a method like the following:
public void setActiveServers(int percent)
{
    java.util.List<Server> servers = (java.util.List<Server>)getObjects(Server.class);
    java.util.Collections.shuffle(servers);
    int nogos = servers.size()*percent/100;
    for (int i=0; i<servers.size(); i++) servers.get(i).setActive(i>=nogos);
}
Jemy Jemy

2021/5/13

#
danpost wrote...
Jemy wrote...
I am thinking of selecting a percentage of the servers that will assumed a failed state. I have not been able to think through on how to write the code to select lets say 2 from the whole servers. eg. if you select 0% as failed all server runs but if you select 10% then 10% of server will assume a failed state and will not participate in the simulation etc.
Maybe your world could use a method like the following:
public void setActiveServers(int percent)
{
    java.util.List<Server> servers = (java.util.List<Server>)getObjects(Server.class);
    java.util.Collections.shuffle(servers);
    int nogos = servers.size()*percent/100;
    for (int i=0; i<servers.size(); i++) servers.get(i).setActive(i>=nogos);
}
please where will I call this method; in the worlds constructor or serverPopulation method?
danpost danpost

2021/5/13

#
Jemy wrote...
please where will I call this method; in the worlds constructor or serverPopulation method?
Well, the servers need to already be in the world. What do you think?
Jemy Jemy

2021/5/13

#
danpost wrote...
Jemy wrote...
please where will I call this method; in the worlds constructor or serverPopulation method?
Well, the servers need to already be in the world. What do you think?
danpost wrote...
Jemy wrote...
please where will I call this method; in the worlds constructor or serverPopulation method?
Well, the servers need to already be in the world. What do you think?
i think this method will replace the serverpopulation
There are more replies on the next page.
1
2