Beispiel #1
0
  /**
   * @param args[0] : nom du fichier contenant le labyrinthe
   * @param args[1] : nombre de pas d'évaluation
   * @param args[2] : nombre de règles par controleur
   */
  public static void main(String[] args) {

    String labyFile = "goal.mze"; // args[0];
    int nbSteps = 50; // Integer.parseInt(args[1]);
    // int nbRules = 10; // Integer.parseInt(args[2]);
    try {
      Labyrinthe laby = ChargeurLabyrinthe.chargerLabyrinthe(labyFile);

      // IControleur sc = ControlFactory.createControleur(nbRules);
      IControleur sc = ControlFactory.createControleurSmart();
      Simulation sim = new Simulation(laby, sc);
      System.out.println("Regles du controleur :");
      System.out.println(sc);
      System.out.println("\nLabi avant :");
      System.out.println(sim.getLaby());
      System.out.println("\nNombre de points :");
      System.out.println(sim.mesurePerf(nbSteps, System.out));
      System.out.println("\nLabi apres :");
      System.out.println(sim.getLaby());

    } catch (IOException e) {
      System.out.println("Problème de chargement du labyrinthe" + e);
      System.exit(1);
    }
  }
  /**
   * This method defines what an Customer does: The customer attempts to enter the restaurant (only
   * successful when the restaurant has a free table), place its order, and then leave the
   * restaurant when the order is complete.
   */
  public void run() {

    Simulation.logEvent(SimulationEvent.customerStarting(this));
    try {

      tableSpace.acquire();

      Simulation.logEvent(SimulationEvent.customerEnteredCoffeeShop(this));

      Simulation.logEvent(SimulationEvent.customerPlacedOrder(this, this.order, this.orderNum));

      Simulation.orders.put(new FoodOrder(this.orderNum, this.order, this));

      while (Simulation.custMap.get(this) == false) {
        Thread.sleep(15);
      }

      Simulation.logEvent(SimulationEvent.customerReceivedOrder(this, this.order, this.orderNum));

      Simulation.logEvent(SimulationEvent.customerLeavingCoffeeShop(this));

      tableSpace.release();

    } catch (InterruptedException e) {

    }
  }
  public static void main(String[] args) {
    Simulation defaultSimulation =
        new Simulation(10, 100, 100) {
          @Override
          public void Simulate() {
            reportEconomyState(0);
            for (long i = 1; i < TOTAL_ITERATIONS; i++) {

              for (Actor actor1 : ACTORS) {
                for (Actor actor2 : ACTORS) {
                  if (!actor1.equals(actor2)) {
                    trade(actor1, actor2);
                  }
                }
              }
              for (Actor actor : ACTORS) {
                actor.produce();
                actor.consume();
              }
              reportEconomyState(i);
            }
          }
        };

    defaultSimulation.Simulate();
  }
  static List<Command> deliver(Simulation sim) {

    List<Command> commands = new ArrayList<>();

    List<Order> orderedSorted = new ArrayList<>(sim.orders.values());
    Collections.sort(orderedSorted, (o1, o2) -> o1.totalWeight - o2.totalWeight);

    mainLbl:
    for (Order order : orderedSorted) {

      for (int p : order.products) {
        System.out.println("Product Id :" + p);
        wareHouseLbl:
        for (Warehouse w : sim.warehouses.values()) {
          //                        System.out.println("Warehouse : products : "+
          // Arrays.toString(w.products));
          if (w.products[p] > 0) {

            Random random = new Random();
            // drone le plus proche du warehouse courant
            Drone d = closestDrone(w, sim.drones.values());
            //                            Drone d = sim.drones.get(0);
            //                            Drone d =
            // sim.drones.get(random.nextInt(sim.drones.size()));

            //                            int nbProducts = Math.min((sim.maxpayload /
            // sim.products.get(p).weight));
            int nbProducts = 1;
            System.out.println(nbProducts);

            long delta = (distance(new int[] {d.row, d.col}, new int[] {w.row, w.col}) + 1);
            sim.turns -= delta;
            if (sim.turns < 0) {
              System.out.println("Turns over :(");
              break mainLbl;
            }
            commands.add(new LoadCommand(d.id, w.id, order.id, p, nbProducts));
            w.products[p] -= nbProducts;
            d.row = w.row;
            d.col = w.col;

            delta = (distance(new int[] {d.row, d.col}, new int[] {order.row, order.col}) + 1);
            sim.turns -= delta;
            if (sim.turns < 0) {
              System.out.println("Turns over :(");
              break mainLbl;
            }
            commands.add(new DeliverCommand(d.id, order.id, p, nbProducts));
            d.row = order.row;
            d.col = order.col;
            break wareHouseLbl;
          }
        }
      }
    }

    return commands;
  }
  @Override
  public Move next(Simulation simulation) throws InterruptedException {
    if (simulation.getBegin() == simulation.getCurrent()) {
      double price = simulation.getQuoteSeries().getClose()[simulation.getBegin()];

      move = new Move(price, price);
    }
    return move;
  }
 @Override
 public boolean touchDown(int screenX, int screenY, int pointer, int button) {
   if (button == Input.Buttons.LEFT) {
     Simulation.get().addObstacle(screenX, Settings.WORLD_MAX_Y - screenY);
   } else if (button == Input.Buttons.RIGHT) {
     Simulation.get().removeObstacle(screenX, Settings.WORLD_MAX_Y - screenY);
   }
   return true;
 }
 public void testIsAdaptableToTickPolicy() {
   final Simulation sim = new Simulation(SimpleTerrain.createExampleTerrain());
   try {
     final SimulationTickPolicy policy = Adaptables.adapt(sim, SimulationTickPolicy.class);
     assertNotNull(policy);
   } finally {
     sim.shutdown();
   }
 }
Beispiel #8
0
 @Override
 public void update(
     float delta,
     float touchX,
     float touchY,
     float width,
     float height,
     boolean touched_down,
     boolean fast_press,
     boolean pressed_back_button) {
   simulation.update(delta);
   simulation.variables(
       touchX, touchY, width, height, touched_down, fast_press, pressed_back_button);
 }
  /** @param args */
  public static void main(String[] args) {

    // Welcome
    System.out.println("Welcome to my traffic simulation project.");
    System.out.println("Choose from the following options:");
    System.out.println("start - Start a simulation");
    System.out.println("stop - Stop a simulation");
    System.out.println("0 - clear");
    System.out.println("1 - init null hypothesis");
    System.out.println("2 - init alt hypothesis");
    System.out.println("3 - step 1");
    System.out.println("4 - step n (1000x)");
    System.out.println("5 - step continuous");
    System.out.println("6 - print results");
    System.out.println("exit - Exit the program");
    System.out.println("");

    // simulation initialization
    Simulation s = new Simulation();

    // input initialization
    String command = "";
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    while (!command.equals("exit")) {
      System.out.print("Input: ");
      try {
        command = reader.readLine();
      } catch (IOException e) {
        System.out.println("Invalid input!");
        e.printStackTrace();
      }

      // parse int command
      if (command.matches("\\d+")) {
        mode = Integer.parseInt(command);
      } else {
        // do nothing
      }

      if (command.matches("start")) {
        s.start();
      }

      if (command.matches("stop")) {
        run = false;
      }
    }
  }
Beispiel #10
0
  public void Game_Finished(int level) {
    game_finished = true;
    this.level = level;
    if (simulation.game_won()) {
      prefs.putInteger("Level_26_Game", 2);
      if (prefs.getInteger("Level_10_Game", 0) == 2) {

      } else {
        prefs.putInteger("Level_10_Game", 1);
      }
      if (prefs.getInteger("Level_21_Game", 0) == 2) {

      } else {
        prefs.putInteger("Level_21_Game", 1);
      }
      if (prefs.getInteger("Level_27_Game", 0) == 2) {

      } else {
        prefs.putInteger("Level_27_Game", 1);
      }
      if (prefs.getInteger("Level_31_Game", 0) == 2) {

      } else {
        prefs.putInteger("Level_31_Game", 1);
      }
      prefs.flush();
    }
  }
Beispiel #11
0
 /** Generates synthetic data with only normal users. */
 private static void normalsOnly() {
   long start = System.nanoTime();
   Simulation.run(KeepObjectsInMemory.instance());
   //		Simulation.run(SaveToDatabase.instance());
   long end = System.nanoTime();
   System.out.println((end - start) / 1000000);
   //		ClusterAnalysis.clusterSimData("");
 }
Beispiel #12
0
 public String[] getArgs() {
   String[] args = simu.getArgs();
   // TODO: Little hack to add the current instance number to the properties sent to the JiST
   // server
   // args[1] =
   // args[1].concat(ExtendedProperties.DEFAULT_SEPARATOR+"ducks.simulation.instance.num="+instanceNum);
   return args;
 }
 public static void main(String[] args) {
   int i;
   int cases = 5;
   for (i = 1; i <= cases; ++i) {
     System.out.println("Now it's test case " + i + ": ");
     Simulation.simulate();
     System.out.println();
   }
 }
  @Test
  public void simplest() {

    StaticPlayer player = new StaticPlayer();
    Simulation simulation = new Simulation(1000, 1000, 1, Integer.MAX_VALUE, 1, player);

    product = simulation.createProduct(0, 1);

    warehouse = simulation.addWarehouse(0, 0, 0);
    warehouse.setProductQuantity(product.getId(), 1);

    order = simulation.addOrder(0, 0, 100);
    order.add(product);

    player.submit(0, new Load(warehouse, product, 1));
    player.submit(0, new Deliver(order, product, 1));

    simulation.start();
  }
Beispiel #15
0
  Main init() {

    // Create a chart to monitor the infection progress rate
    final XYLineChart chart =
        new XYLineChart("Infection Rate", 5.0, "Infected Nodes (%)", "time(s)");
    chart.setYRange(false, 0, 100);
    chart.setSeriesLinesAndShapes("s0", true, true);

    Gui.setFrameRectangle("MainFrame", 0, 0, 480, 480);
    Gui.setFrameRectangle("Infection Rate", 484, 0, 480, 480);

    // Create the simulation nodes
    for (int i = 0; i < TOTAL_NODES; i++) new Node();

    // Initialize the simulation nodes
    for (Node i : NodeDB.nodes()) i.init();

    NodeDB.randomNode().infect();

    // Sets up a periodic task that, at one second intervals, computes and shows the percentage of
    // infected nodes in the system
    // Stops the simulation when it detects that every node is infected...
    new PeriodicTask(1.0) {
      public void run() {
        double T = 0, N = 0;
        for (Node n : NodeDB.nodes()) {
          if (n.infected) T++;
          N++;
        }
        chart.getSeries("s0").add(Simulation.currentTime(), 100.0 * T / N);
        if (N == T) stop();
      };
    };

    // From time to time, select a random node to go fail and go offline...
    new Task(0) {
      public void run() {
        NodeDB.randomNode().crash();
        reSchedule(0.5 + 0.5 * rg.nextDouble()); // schedules a new execution of this task...
      }
    };

    // From time to time, create a new node. If the rate of births and deaths is the same,
    // the size of the system should stay constant on average.
    new Task(0) {
      public void run() {
        new Node().init();
        reSchedule(0.5 + 0.5 * rg.nextDouble()); // schedules a new execution of this task...
      }
    };

    super.setSimulationMaxTimeWarp(2.0);

    return this;
  }
 @Override
 public void respondToEvent(Event e, Simulation s) {
   if (e.getType() == s.working) {
     System.out.println(e.getTime() + " machine working");
     working = true;
     // double timeToNextFailure = Math.abs(s.generator.nextGaussian()*MTTFvariance+MTTF);
     double timeToNextFailure = s.traceMachineNextFail.removeFirst();
     e.setTime(s.now + timeToNextFailure);
     e.setType(s.failure);
     s.scheduleEvent(e);
     return;
   }
   if (e.getType() == s.failure) {
     System.out.println(e.getTime() + " machine failure");
     working = false;
     e.setTime(s.now);
     e.setHandler(s.r);
     e.setType(s.startRepair);
     s.scheduleEvent(e);
     return;
   }
 }
Beispiel #17
0
 public String getSim() {
   return simu.getSim();
 }
Beispiel #18
0
 public int getIdentifier() {
   return simu.getIdentifier();
 }
Beispiel #19
0
 public ExtendedProperties getSimuConfig() {
   return simu.getSimuConfig();
 }
Beispiel #20
0
 /**
  * Call, if sim instance could not be executed as intended, e.g. because RMI link to server was
  * broken. This means of course, that the instance has to be executed again, whereas it must not
  * be repeated when a simulation internal failure occured that is not due to DUCKS (in this case,
  * finalize(FAILED) would be used)
  */
 public void recall() {
   simu.recallInstance(this);
 }
Beispiel #21
0
 /**
  * Triggers the simulator's mouse_dragged function
  *
  * @param me MouseEvent
  */
 public void mouseDragged(MouseEvent me) {
   sim.mouse_dragged(me);
 }
 public boolean _readState(String _filename) {
   return _simulation.readState(_filename, getCodeBase());
 }
Beispiel #23
0
 /**
  * Triggers the simulator's mouse_pressed function
  *
  * @param me MouseEvent
  */
 public void mousePressed(MouseEvent me) {
   sim.mouse_pressed(me);
 }
Beispiel #24
0
  //	private static void whileAway2() {
  //		ConstructGraph.allCombosFraudOnlyMultiDB();
  //		ConstructGraph.allCombosMultiDB();
  //	}
  // has loops for running big batches of simulations
  private static void whileAway1() {
    Strategy trevathan = new TrevathanStrategy(0.95, 0.85, 0.85);
    Strategy waitStart = new WaitStartStrategy(0.95, 0.85, 0.85);
    Strategy lowPrice = new LowPriceStrategy();

    //		for (int i : Arrays.asList(0)) {
    //			String databaseName = "syn_normal_20k_" + i;
    //			DBConnection.createDatabase(databaseName);
    //			SimulationCreateTableStmts.createSimulationTables(databaseName);
    //			// run the simulation and store everything into the database
    //			Simulation.run(SaveToDatabase.instance(databaseName), 20000);
    //			System.out.println("finished run " + i);
    //		}

    //		AgentAdder simpleWS = SimpleShillPair.getAgentAdder(200, waitStart); // can use 20, since
    // each submits 10 auctions.
    //		for (int i : Arrays.asList(1,2,3,4)) {
    //			String databaseName = "syn_simpleWS_20k_" + i;
    //			// construct database and tables to store simulation data
    //			DBConnection.createDatabase(databaseName);
    //			SimulationCreateTableStmts.createSimulationTables(databaseName);
    //
    //			// run the simulation and store everything into the database
    //			Simulation.run(SaveToDatabase.instance(databaseName), 20000, simpleWS);
    //			System.out.println("finished run " + i);
    //		}

    ////		AgentAdder hybridBoth = CollusionController.getAgentAdder(10 * 5, waitStart,
    // PuppetClusterBidderCombined.getFactory());
    //		AgentAdder hybridBoth = CollusionController.getAgentAdder(10 * 3, waitStart,
    // PuppetClusterBidderSellerCombined.getFactory());
    ////		Main.run(SaveToDatabase.instance(), hybrid);
    //		for (int i : Arrays.asList(0)) {
    //			String databaseName = "syn_hybridBothBS_20k_" + i;
    //			// construct database and tables to store simulation data
    ////			DBConnection.createDatabase(databaseName);
    ////			SimulationCreateTableStmts.createSimulationTables(databaseName);
    //
    //			// run the simulation and store everything into the database
    //			Simulation.run(SaveToDatabase.instance(databaseName), 20000, hybridBoth);
    //			System.out.println("finished run " + i);
    //		}

    AgentAdder hybridBothVGS =
        CollusionController.getAgentAdderVaryGroupSize(
            10 * 3, waitStart, PuppetClusterBidderSellerCombined.getFactory());
    //		Main.run(SaveToDatabase.instance(), hybrid);
    for (int i : Arrays.asList(5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)) {
      String databaseName = "syn_hybridBothVGS_20k_" + i;
      // construct database and tables to store simulation data
      DBConnection.createDatabase(databaseName);
      SimulationCreateTableStmts.createSimulationTables(databaseName);

      // run the simulation and store everything into the database
      Simulation.run(SaveToDatabase.instance(databaseName), 20000, hybridBothVGS);
      System.out.println("finished run " + i);
    }

    AgentAdder hybrid =
        HybridT.getAgentAdder(10 * 5, waitStart, PuppetClusterBidderCombined.getFactory());
    //		Main.run(SaveToDatabase.instance(), hybrid);
    for (int i :
        Arrays.asList(
            20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39)) {
      String databaseName = "syn_hybridNormalEE_20k_" + i;
      // construct database and tables to store simulation data
      DBConnection.createDatabase(databaseName);
      SimulationCreateTableStmts.createSimulationTables(databaseName);

      // run the simulation and store everything into the database
      Simulation.run(SaveToDatabase.instance(databaseName), 20000, hybrid);
      System.out.println("finished run " + i);
    }

    //		AgentAdder repFraud = RepFraudController.getAgentAdder(1, 40, 500);
    //		for (int i : Arrays.asList(3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19)) {
    //			String databaseName = "syn_repFraud_20k_small_" + i;
    //			// construct database and tables to store simulation data
    //			DBConnection.createDatabase(databaseName);
    //			SimulationCreateTableStmts.createSimulationTables(databaseName);
    //
    //			// run the simulation and store everything into the database
    //			Simulation.run(SaveToDatabase.instance(databaseName), 20000, repFraud);
    //
    //			System.out.println("finished run " + i);
    //		}

    //		AgentAdder repFraud_3 = RepFraudController.getAgentAdder(3, 40, 800);
    //		for (int i : Arrays.asList(10,11,12,13,14,15,16,17,18,19)) {
    //			String databaseName = "syn_repFraud_20k_3_" + i;
    //			// construct database and tables to store simulation data
    //			DBConnection.createDatabase(databaseName);
    //			SimulationCreateTableStmts.createSimulationTables(databaseName);
    //
    //			// run the simulation and store everything into the database
    //			Simulation.run(SaveToDatabase.instance(databaseName), 20000, repFraud_3);
    //
    //			System.out.println("finished run " + i);
    //		}

  }
Beispiel #25
0
 /**
  * constructor for grid class
  *
  * @param width
  * @param height
  * @param sim
  * @param map
  */
 public Grid(int width, int height, Simulation sim, Map<String, Double> map) {
   mySimulation = sim;
   myCells = mySimulation.setUpCells(this, width, height, map);
   initNeighbors();
 }
Beispiel #26
0
 public static void main(String[] args) {
   Simulation app = new Simulation();
   app.start();
 }
 public boolean _setVariables(String _command, String _delim, String _arrayDelim) {
   return _simulation.setVariables(_command, _delim, _arrayDelim);
 }
/*
Beispiel #29
0
 /**
  * Finalize simulation: simulation instance has succeeded or failed definitely. This won't change
  * any more.
  *
  * @param newState DONE or FAILED
  */
 private void finalize(int newState) {
   state = newState;
   simu.finalizeInstance(this);
 }
Beispiel #30
0
 /**
  * Triggers the simulator's mouse_released function
  *
  * @param me MouseEvent
  */
 public void mouseReleased(MouseEvent me) {
   sim.mouse_released(me);
 }