Flocking_large.java 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import sim.engine.Steppable;
  2. import sim.util.Bag;
  3. import sim.util.Double2D;
  4. import sim.field.continuous.Continuous2D;
  5. import sim.engine.SimState;
  6. import sim.engine.RandomSequence;
  7. public class Flocking_large extends SimState
  8. {
  9. public Continuous2D flockers;
  10. public double width;
  11. public double height;
  12. public int numFlockers;
  13. public double cohesion;
  14. public double avoidance;
  15. public double consistency;
  16. public double momentum;
  17. public double neighborhood;
  18. public long startTime;
  19. public Flocking_large(final long seed) {
  20. super(seed);
  21. this.width = 150.0;
  22. this.height = 150.0;
  23. this.numFlockers = 400;
  24. this.neighborhood = 15.0;
  25. this.cohesion = 0.03;
  26. this.avoidance = 0.015;
  27. this.consistency = 0.05;
  28. this.momentum = 1.0;
  29. }
  30. public void start() {
  31. super.start();
  32. Steppable[] array_agents = new Steppable[numFlockers];
  33. int count = 0;
  34. this.flockers = new Continuous2D(this.neighborhood / 1.5, this.width, this.height);
  35. for (int x = 0; x < this.numFlockers; ++x) {
  36. final Double2D location = new Double2D(this.random.nextDouble() * this.width, this.random.nextDouble() * this.height);
  37. final Double2D vel = new Double2D(this.random.nextDouble()*2-1, this.random.nextDouble()*2-1);
  38. final Flocker_large flocker = new Flocker_large(location, vel);
  39. this.flockers.setObjectLocation((Object)flocker, location);
  40. flocker.flockers = this.flockers;
  41. flocker.theFlock = this;
  42. array_agents[count] = flocker;
  43. ++count;
  44. }
  45. this.schedule.scheduleRepeating(new RandomSequence(array_agents));
  46. this.startTime = System.nanoTime();
  47. }
  48. @Override
  49. public void finish() {
  50. super.finish();
  51. long endTime = System.nanoTime();
  52. System.out.println("JobTime: " + (endTime - this.startTime));
  53. }
  54. public static void main(final String[] args) {
  55. doLoop((Class)Flocking_large.class, args);
  56. System.exit(0);
  57. }
  58. }