Examples of ICARulesGrid


Examples of org.jamesii.model.carules.grid.ICARulesGrid

    Object iS = map.get("initialState");
    if (!(iS instanceof ICARulesGrid)) {
      return;
    }

    ICARulesGrid grid = (ICARulesGrid) iS;
    // dimension
    int[] dimensions = grid.getSize();

    // TODO sr137: change return type to boolean or result set or similar
    if (dimensions.length != 2) {
      return;
    }

    File f = Files.getFileFromURI(location);
    try {
      BufferedWriter writer =
          new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f),
              "UTF8"));

      try {

        for (int d = 0; d < dimensions.length; d++) {
          if (d != 0) {
            writer.write(" ");
          }
          writer.write(String.valueOf(dimensions[d]));
        }
        writer.write("\n");

        // states
        List<Integer> states = createStateMapping(grid);
        for (int p = 0; p < states.size(); p++) {
          if (p != 0) {
            writer.write("\t");
          }
          writer.write((char) (states.get(p) + 'a') + ";" + states.get(p));
        }
        writer.write("\n");

        // grid
        // TODO sr137: store grid

        for (int y = 0; y < dimensions[1]; y++) {
          for (int x = 0; x < dimensions[0]; x++) {
            writer.write(grid.getState(new int[] { x, y }) + 'a');
          }
          writer.write("\n");
        }
      } catch (IOException e) {
        SimSystem.report(e);
View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

  @Override
  public void instrumentModel(IModel model,
      IComputationTaskConfiguration simConfig) {
    model.setMediator(new Mediator());
    ICARulesModel m = (ICARulesModel) model;
    ICARulesGrid g = m.getGrid();

    // try to extract a custom cell renderer from the simulation configuration
    Object userParameters = simConfig.getParameters().get("user.parameters");
    IGridCellRenderer renderer = null;
    if (userParameters instanceof IGridCellRenderer) {
      renderer = (IGridCellRenderer) userParameters;
    }

    // System.out.println("Instrumenting the model");

    IObserver<? extends IObservable> obs = null;

    if (g.getSize().length == 1) {
      // create the observer to feed the grid "1d"
      obs = new CA1DStateModelObs(renderer);
    }

    if (g instanceof IGrid2D) {
View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

  @Override
  protected void nextStep() {
    ICARulesModel m = this.getModel();

    // get the grid from the model
    ICARulesGrid grid = m.getGrid();

    // make a copy of the grid, and thus of each cell's state
    ICARulesGrid oldGrid = grid.cloneGrid();

    // now iterate over all cells in the copy of the grid
    for (ICACell<?> cell : oldGrid.getCellList()) {

      // get the current state
      int current = cell.getState();

      // get the neighbours of the current cell
      INeighborStates<Integer> neighbours =
          oldGrid.getNeighborStates(m.getBaseRules().getNeighborhood(current),
              false, cell.getPosition());

      // compute the new state based on the current one, and the states of the
      // neighbours
      int next = m.getBaseRules().getNextState(current, neighbours);
View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

  @Override
  protected void nextStep() {
    ICARulesModel m = this.getModel();

    // get the grid from the model
    ICARulesGrid grid = m.getGrid();

    Runtime r = Runtime.getRuntime();

    int procs = r.availableProcessors();
View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

  @Override
  protected void nextStep() {
    ICARulesModel m = this.getModel();

    // get the grid from the model
    ICARulesGrid grid = m.getGrid();

    // make a copy of the grid, and thus of each cell's state
    ICARulesGrid oldGrid = grid.cloneGrid();

    Runtime r = Runtime.getRuntime();

    int procs = r.availableProcessors();

    // System.out.println("Going to use " + procs + " processors");
    int[] size = oldGrid.getSize();
    int cellCount = 1;
    for (int element : size) {
      cellCount *= element;
    }

View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

      Integer i = Integer.valueOf(stateMapping.substring(2));
      states.put(c, i);
    }

    // Should be enough states for most models
    ICARulesGrid result =
        GridProvider.createGrid(dimension.length, dimension, 0, DEFAULT_NUMBER_OF_STATES);

    int y = -1;
    int x;

    while (st.hasMoreTokens()) {
      String line = st.nextToken();
      y++;
      x = -1;
      for (int c = 0; c < line.length(); c++) {
        x++;
        Character ch = line.charAt(c);
        // if (!states.containsKey(ch)) {
        // states.put(ch, ++lastState);
        // }
        result.setState(states.get(ch), x, y);
      }
    }

    Map<String, Object> res = new HashMap<>();
    res.put("initialState", result);
View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

   *          the initial grid
   * @return the i grid
   */
  private static ICARulesGrid createGrid(BaseGridFactory factory,
      int[] gridSize, List<?> states, List<ICACell> initialGrid) {
    ICARulesGrid result =
        GridProvider.createGrid(factory, gridSize.length, gridSize, 0,
            states.size());

    for (ICACell c : initialGrid) {
      result.setState(c.getState(), c.getPosition());
    }

    return result;
  }
View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

  @Override
  protected void nextStep() {
    ICARulesModel m = this.getModel();

    // get the grid from the model
    ICARulesGrid grid = m.getGrid();

    // update number of processors occasionally
    procCountRefresh++;
    if (procCountRefresh == 1000) {
      Runtime r = Runtime.getRuntime();
View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

      Object t = parameters.get("initialState");

      t = t instanceof String ? loadInitialState((String) t) : t;

      if (t instanceof ICARulesGrid) {
        ICARulesGrid grid = (ICARulesGrid) t;
        // set size from parameters
        standardSize = grid.getSize();

        // set cells from parameters
        cellList = grid.getCellList();
      }

      CARulesModel model = null;
      if (gridParameters == null) {
        model =
View Full Code Here

Examples of org.jamesii.model.carules.grid.ICARulesGrid

      stream = new FileInputStream(fileName);
      if (stream.skip(skipChars) != skipChars) {
        return null;
      }

      ICARulesGrid grid = new Grid2D(new int[] { width, height }, 0);

      for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
          int s = stream.read();
          grid.setState(s, new int[] { x, y });
        }
        stream.read();
      }

      return grid;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.