All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sim.app.crowd3d.CrowdSim Maven / Gradle / Ivy

Go to download

MASON is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs. MASON contains both a model library and an optional suite of visualization tools in 2D and 3D.

The newest version!
/*
  Copyright 2006 by Sean Luke and George Mason University
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/

package sim.app.crowd3d;
import sim.engine.*;
import sim.util.*;
import sim.field.continuous.*;


public class CrowdSim extends SimState
    {
    private static final long serialVersionUID = 1;

    public double spaceHeight = 20;
    public double spaceWidth = 20;
    public double spaceDepth = 20;
    public int boidCount =0;
    public final int STEPS_BETWEEN_INSERTS = 200;
    public double maxFnVal;

    public Continuous3D boidSpace = new Continuous3D(Agent.SIGHT, spaceWidth, spaceHeight, spaceDepth);
                
    public static void main(String[] args)
        {
        doLoop(CrowdSim.class, args);
        System.exit(0);
        }    

    public CrowdSim(long seed)
        {
        super(seed);
        maxFnVal = Math.min(spaceHeight, Math.min(spaceWidth, spaceDepth))/2;
        }
    
    private void spawnBoid()
        {
        Agent boid = new Agent();
        boidSpace.setObjectLocation(boid,
            new Double3D(       random.nextDouble()*spaceWidth,
                random.nextDouble()*spaceHeight,
                random.nextDouble()*spaceDepth));
        boid.setStopper(schedule.scheduleRepeating(boid));
        boidCount++;
        }

    protected void killBoid()
        {
        Agent victim = (Agent)boidSpace.allObjects.objs[(int)(random.nextDouble()*boidCount)];
        victim.stop();
        boidSpace.remove(victim);
                
        }
        
    public void start()
        {
        super.start();  // clear out the schedule
        
        boidSpace = new Continuous3D(Agent.SIGHT, spaceWidth, spaceHeight, spaceDepth);
        //*
        Steppable spawner = new Steppable(){public void step(SimState state){spawnBoid();}};
        //        Steppable killer = new Steppable(){public void step(SimState state){killBoid();}};
        schedule.scheduleRepeating(Schedule.EPOCH,1,spawner,STEPS_BETWEEN_INSERTS);
        /*/
          for(int i=0;i<10;++i)
          spawnBoid();
        //*/
        }
    }
    
    
    
    
    




© 2015 - 2025 Weber Informatics LLC | Privacy Policy