// *******initialize******* domain with cells
  void resetCells() {
    // int radius=50; dont think this is used
    Cells = new int[size][size];
    carriedmutation = new int[size][size];

    // Fill the domain with healthy cells 0's first.
    for (int i = 0; i < size; i++)
      for (int j = 0; j < size; j++) {
        Cells[i][j] = 0;
        carriedmutation[i][j] = 0;
      }

    Cells[centre][centre] = 1; // initialize with a stem cell if you like
    carriedmutation[centre][centre] = 1; // the first cancer cell carries the tag '1' to start

    genomeToMod = new StringBuilder(carriedGenome[centre][centre]);
    genomeToMod.setCharAt(mutationNum - 1, '1'); //  daughter carries new carriedGenome
    carriedGenome[centre][centre] = genomeToMod;

    // genomeToMod = carriedGenome[centre][centre];
  }
Beispiel #2
0
  public void solve() throws Exception {
    int x = sc.nextInt();
    int y = sc.nextInt();
    StringBuilder sb = new StringBuilder();
    String p = null;
    String m = null;
    if (x >= 0) {
      p = "E";
      m = "W";
    } else {
      p = "W";
      m = "E";
    }
    x = abs(x);

    for (int i = 0; i < x; i++) {
      sb.append(m + p);
    }
    if (y >= 0) {
      p = "N";
      m = "S";
    } else {
      p = "S";
      m = "N";
    }
    y = abs(y);
    for (int i = 0; i < y; i++) {
      sb.append(m + p);
    }
    out.println(sb);
  }
  // ******
  public void reset() {
    // consumption = new float [size][size];
    // Oxygen = new float [size][size];
    Age = new int[size][size];
    stemBirthCounter = new int[size][size];
    stemBirthsTotal = new int[size][size];
    stemDeathCounter = new int[size][size];
    // TACDeathCounter = new int [size][size];
    // TACBirthCounter = new int [size][size];
    StringBuilder initGenome = new StringBuilder();
    for (int i = 0; i < lengthGenome; i++) {
      initGenome.append("0");
    }
    ;
    for (int i = 0; i < size; i++)
      for (int j = 0; j < size; j++) {
        carriedGenome[i][j] = (StringBuilder) initGenome;
        // carriedGenome[i][j] = (StringBuilder) initGenome;
        // Oxygen[i][j]=initOxygen;
        Age[i][j] = 0;
        stemBirthCounter[i][j] = 0;
      }

    resetCells();
  }
Beispiel #4
0
 public int totalNQueens(int n) {
   StringBuilder[] board = new StringBuilder[n];
   for (int i = 0; i < n; i++) {
     board[i] = new StringBuilder();
     for (int j = 0; j < n; j++) {
       board[i].append('.');
     }
   }
   for (int i = 0; i < n / 2; i++) {
     board[0].setCharAt(i, 'Q');
     dfs(n, 1, board);
     board[0].setCharAt(i, '.');
   }
   ArrayList<String[]> aux = new ArrayList<String[]>();
   for (String[] k : res) {
     String[] tmp = new String[n];
     for (int i = 0; i < n; i++) {
       StringBuilder sb = new StringBuilder(k[i]).reverse();
       tmp[i] = sb.toString();
     }
     aux.add(tmp);
   }
   res.addAll(aux);
   if (n % 2 != 0) {
     board[0].setCharAt(n / 2, 'Q');
     dfs(n, 1, board);
     board[0].setCharAt(n / 2, '.');
   }
   return res.size();
 }
Beispiel #5
0
  // **************************************************
  // **************************************************
  // **************************************************
  //                  MAP STUFF
  // **************************************************
  // **************************************************
  // **************************************************
  private static void generateMap(String mapName) {
    try {
      PrintWriter writer = new PrintWriter(mapName);

      final char[] map = new char[rows * cols];
      Arrays.fill(map, '.');

      for (WareHouse warehouse : warehouses) {
        map[warehouse.x * cols + warehouse.y] = 'w';
      }

      for (Order order : orders) {
        map[order.x * cols + order.y] = 'o';
      }

      for (int r = 0; r < rows; r++) {
        final StringBuilder stringBuilder = new StringBuilder();
        for (int c = 0; c < cols; c++) {
          stringBuilder.append(map[r * cols + c]);
        }
        stringBuilder.append('\n');
        writer.println(stringBuilder.toString());
      }

      writer.close();
    } catch (IOException e) {
      System.out.println("error writing file " + e.getMessage());
    }
  }
Beispiel #6
0
 public void run() {
   // Scanner sc = new Scanner(System.in);
   Scanner sc = new Scanner();
   StringBuilder sb = new StringBuilder(1000000);
   // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
   final int N = sc.nextInt();
   final int M = sc.nextInt();
   final int K = (int) floor(sqrt(N));
   final int[] A = new int[N + 1];
   A[0] = 1;
   for (int i = 1; i <= N; i++) A[i] = sc.nextInt();
   final int[] next = new int[N + 1];
   final int[] step = new int[N + 1];
   final int[] last = new int[N + 1];
   for (int i = N; i > 0; i--) {
     int j = i + A[i];
     if (j > N || j / K > i / K) {
       last[i] = i;
       step[i] = 1;
       next[i] = j;
     } else {
       last[i] = last[j];
       step[i] = step[j] + 1;
       next[i] = next[j];
     }
   }
   for (int t = 0; t < M; t++)
     if (sc.nextInt() == 1) {
       int i = sc.nextInt();
       int j = 0;
       int k = 0;
       while (i <= N) {
         j += step[i];
         k = last[i];
         i = next[i];
       }
       sb.append(k).append(' ').append(j).append('\n');
       // System.out.println(k + " " + j);
     } else {
       int k = sc.nextInt();
       int b = k / K * K;
       A[k] = sc.nextInt();
       for (int i = min(b + K - 1, N); i >= b; i--) {
         int j = i + A[i];
         if (j > N || j / K > i / K) {
           last[i] = i;
           step[i] = 1;
           next[i] = j;
         } else {
           last[i] = last[j];
           step[i] = step[j] + 1;
           next[i] = next[j];
         }
       }
     }
   // System.out.flush();
   System.out.print(sb);
 }
 public String ns() {
   int b = skip();
   StringBuilder sb = new StringBuilder();
   while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != // ' ')
     sb.appendCodePoint(b);
     b = readByte();
   }
   return sb.toString();
 }
 private String ns1() {
   int b = skip();
   StringBuilder sb = new StringBuilder();
   while (!(isSpaceChar(b) && b != ' ')) { // when nextLine,
     sb.appendCodePoint(b);
     b = readByte();
   }
   return sb.toString();
 }
Beispiel #9
0
 private static void addDeliverCommand(
     Drone drone, Order order, int productType, int productNumber) {
   StringBuilder stringBuilder = new StringBuilder(5);
   stringBuilder.append(drone.id);
   stringBuilder.append(' ');
   stringBuilder.append('D');
   stringBuilder.append(' ');
   stringBuilder.append(order.id);
   stringBuilder.append(' ');
   stringBuilder.append(productType);
   stringBuilder.append(' ');
   stringBuilder.append(productNumber);
   commands.add(stringBuilder.toString());
 }
Beispiel #10
0
 private static void addLoadCommand(
     Drone drone, WareHouse wareHouse, int productType, int productNumber) {
   StringBuilder stringBuilder = new StringBuilder(5);
   stringBuilder.append(drone.id);
   stringBuilder.append(' ');
   stringBuilder.append('L');
   stringBuilder.append(' ');
   stringBuilder.append(wareHouse.id);
   stringBuilder.append(' ');
   stringBuilder.append(productType);
   stringBuilder.append(' ');
   stringBuilder.append(productNumber);
   commands.add(stringBuilder.toString());
 }
  // main CELL CA loop************
  public boolean iterateCells() {
    /*
    	// modify consumption matrix
    	    	for (int i=0;i<size;i++)
    	        for (int j=0;j<size;j++) consumption[i][j] = consumptionBasal[Cells[i][j]];
    */
    //
    if (cellList == null) cellList = new Bag(size * size);
    for (int i = 0; i < size; i++)
      for (int j = 0; j < size; j++) {
        if (Cells[i][j]
            < 4) { // All tumour cell types have Cell > 0, now 0 corresponds to 'healthy cells' that
          // consume at basal rate only
          int[] p = new int[2];
          p[0] = i;
          p[1] = j;
          cellList.add(p);
          if (Cells[i][j] == 1) {
            stem_cells_this_TS++;
          } else if (Cells[i][j] == 2 || Cells[i][j] == 3) {
            non_stem_cells_this_TS++;
          }
        }
      }

    while (cellList.size() != 0) {
      // Select the next lattice element at random
      int randomElemIndex = 0;
      if (cellList.size() > 1) randomElemIndex = random.nextInt(cellList.size() - 1);
      int[] point = (int[]) cellList.get(randomElemIndex);
      int rI = point[0];
      int rJ = point[1];

      cellList.remove(randomElemIndex); // Remove it from the cell list
      int cell = Cells[rI][rJ];

      // Cell death
      // if ((Oxygen[rI][rJ]<hypoxia)) {
      if ((random.nextFloat() < deathprob) && Cells[rI][rJ] > 0) { // x% chances of dying
        Age[rI][rJ] = 0;
        if (Cells[rI][rJ] == 1) stemDeathCounter[rI][rJ]++;
        if (Cells[rI][rJ] < 4) {
          // TACDeathCounter[rI][rJ]++;
          Cells[rI][rJ] = 4; // was 0, now making necrotic area (truly empty)
          deaths++;
          stemBirthCounter[rI][rJ] = 0;
          carriedmutation[rI][rJ] = 0; // empty space now has no mutations
          carriedGenome[rI][rJ] = initGenome; // empty space now has no mutations
        }
      } else if ((cell == 3)
          && (Age[rI][rJ]
              > 100 * maxMatureCellAge)) { // added * to allow for an update each celltimestep/x
        // **************************
        Age[rI][rJ] = 0;
        Cells[rI][rJ] = 4; // was 0, now making necrotic area (truly empty)
        // TACDeathCounter[rI][rJ]++;
        deaths++;
      } else if ((radiotherapy) && (cell == 2) && (random.nextFloat() > Oxygen[rI][rJ])) {
        // Radiotherapy
        Age[rI][rJ] = 0;
        if (Cells[rI][rJ] == 1) stemDeathCounter[rI][rJ]++;
        if ((Cells[rI][rJ] == 2) || (Cells[rI][rJ] == 3))
          // TACDeathCounter[rI][rJ]++;
          Cells[rI][rJ] = 4; // make necrotic
        stemBirthCounter[rI][rJ] = 0;
        deaths++;
      }

      // healthy division
      else if ((cell == 0) && (vacantSites(rI, rJ) > 0)) {
        if (proliferation[cell]
            >= random.nextFloat()) { // If tossing the coin we are to proliferate...
          // if (Oxygen[rI][rJ]>prolifThreshold) { // AND the oxygen concentration is enough for
          // division..
          // consumption[rI][rJ]=consumptionDivision[Cells[rI][rJ]];
          int[] daughter = findEmptySite(rI, rJ);
          births++;
          Cells[daughter[0]][daughter[1]] = 0;
          carriedmutation[daughter[0]][daughter[1]] = 0;
          carriedGenome[daughter[0]][daughter[1]] =
              initGenome; // resetting space to healthy cell with no mutations
        }
      }
      // }

      // cancer division
      else if ((vacantSitesCancer(rI, rJ) > 0) && (cell > 0))
        if (proliferation[cell]
            >= random.nextFloat()) { // If tossing the coin we are to proliferate...
          if ((cell == 1)
              || ((cell == 2)
                  && (Age[rI][rJ] < maxProDivisions))) { // AND the cell is stem or TAC ...
            // if (Oxygen[rI][rJ]>prolifThreshold) { // AND the oxygen concentration is enough for
            // division..
            // consumption[rI][rJ]=consumptionDivision[Cells[rI][rJ]];
            int[] daughter = findEmptySiteCancer(rI, rJ); // and there is space (for cancer)
            //    if ((daughter[0]==0) || (daughter[0]==size) ||
            // (daughter[1]==0)||(daughter[1]==size)) {simulationFinished=true;} // stop sim if a
            // cell hits the edge
            births++;
            if (cell == 1) { // stem cell
              stemBirthsTotal[rI][rJ]++;
              stemBirthCounter[rI][rJ]++;
              if (asymmetricRatio > random.nextFloat()) {
                Cells[daughter[0]][daughter[1]] = 1; // placing the stem daughter
                stemBirthCounter[daughter[0]][daughter[1]] =
                    stemBirthCounter[rI][rJ]; // update stem birth counter
                carriedmutation[daughter[0]][daughter[1]] =
                    carriedmutation[rI][rJ]; // inherit mutational status of parent
                carriedGenome[daughter[0]][daughter[1]] =
                    carriedGenome[rI][rJ]; // inherit mutational status of parent
                if (mutfreq > random.nextFloat()) { // small chance of mutation
                  mutationNum++; // advance mutation number
                  System.out.println(
                      +carriedmutation[rI][rJ]
                          + ", "
                          + mutationNum
                          + ", "
                          + stem_cells_this_TS
                          + ", "
                          + non_stem_cells_this_TS
                          + ", "
                          + timestep); // print (parent,child) pair
                  // tree.put(carriedmutation[rI][rJ], mutationNum);
                  // timeTree.put(mutationNum, timestep); // hash table stuff
                  if (0.5 > random.nextFloat()) {
                    carriedmutation[daughter[0]][daughter[1]] = mutationNum;
                    genomeToMod = new StringBuilder(carriedGenome[daughter[0]][daughter[1]]);
                    genomeToMod.setCharAt(
                        mutationNum - 1, '1'); //  daughter carries new carriedGenome
                    carriedGenome[daughter[0]][daughter[1]] = genomeToMod;
                    // System.out.println (carriedGenome[rI][rJ]);
                    // System.out.println (carriedGenome[daughter[0]][daughter[1]]);
                  } // 50:50 mutate new position daughter
                  else {
                    carriedmutation[rI][rJ] = mutationNum; // else mutate original position daughter
                    genomeToMod = new StringBuilder(carriedGenome[rI][rJ]);
                    // genomeToMod = carriedGenome[rI][rJ];
                    carriedGenome[rI][rJ] = genomeToMod;
                    genomeToMod.setCharAt(
                        mutationNum - 1, '1'); //  original carries new carriedGenome
                    // System.out.println (carriedGenome[rI][rJ]);
                    // System.out.println (carriedGenome[daughter[0]][daughter[1]]);
                  }
                }
              } else {
                Cells[daughter[0]][daughter[1]] = 2; // asymmetric division, daughter is TAC
                stemBirthCounter[daughter[0]][daughter[1]] = 0; // reset stem counter
                carriedmutation[daughter[0]][daughter[1]] =
                    carriedmutation[rI][rJ]; // TAC carries parental mutation flag
                carriedGenome[daughter[0]][daughter[1]] = carriedGenome[rI][rJ];
              } // TAC carries parental genome
              // } // redundant from above

              // else { // Only if there's hypoxia induced change of symmetric division ratio
              //    float newASR=asymmetricRatio+0*(hypoxia-Oxygen[rI][rJ]);
              // currently OFF by way of 0 the ^^ multiplier.
              //    if (newASR>random.nextFloat())
              // {Cells[daughter[0]][daughter[1]]=1;stemBirthCounter[daughter[0]][daughter[1]]=stemBirthCounter[rI][rJ];}
              //    else
              // {Cells[daughter[0]][daughter[1]]=2;stemBirthCounter[daughter[0]][daughter[1]]=0;}
              // // Otherwise differentiate
              // }
            } else if (cell == 2) { // non-stem division
              // TACBirthCounter[rI][rJ]++;
              if (Age[rI][rJ] < maxProDivisions - 1) {
                Cells[daughter[0]][daughter[1]] = 2;
                Age[rI][rJ]++;
                Age[daughter[0]][daughter[1]] = Age[rI][rJ];
                carriedmutation[daughter[0]][daughter[1]] =
                    carriedmutation[rI][rJ]; // TAC carries parental mutation flag
                carriedGenome[daughter[0]][daughter[1]] =
                    carriedGenome[rI][rJ]; // TAC carries parental genome
              } else {
                Cells[daughter[0]][daughter[1]] = 3;
                Cells[rI][rJ] = 3;
                Age[rI][rJ] = 0;
                Age[daughter[0]][daughter[1]] = Age[rI][rJ];
                carriedmutation[daughter[0]][daughter[1]] =
                    carriedmutation[rI][rJ]; // TAC carries parental mutation flag
                carriedGenome[daughter[0]][daughter[1]] =
                    carriedGenome[rI][rJ]; // TAC carries parental genome
              }
            }
          }
        } else if (pMotility > random.nextFloat()) { // Migration = not in use
          int[] daughter = findEmptySite(rI, rJ);
          Cells[daughter[0]][daughter[1]] = cell;
          Cells[rI][rJ] = 0;
          Age[daughter[0]][daughter[1]] = Age[rI][rJ];
          Age[rI][rJ] = 0;
          System.err.println("moving " + rI + ", " + rJ);
        }
      // Aging for mature cells
      if (cell == 3) Age[rI][rJ]++;
    }
    return true;
  }
  private static List<String> importGenomeData(
      File genome_text_file, String target_organism, int sex) throws IOException {

    List<String> temp_genome_data =
        new ArrayList<String>(); // The genome data array that contains the sizes of each chromosome
    // int haploid_number; // Used to determine the size of the first dimension in the
    // temp_genome_data array
    boolean found_target_organism =
        false; // Used to determine what action to take when a new header line in the file is found;
    // close if true, keep reading if false
    boolean end_of_genome = false; // True when the Y chromosome has been dealt with

    // Construct BufferedReader from FileReader; search for header line of target organism and
    // obtain the haploid number then create a two dimensional array, size of the first dimension
    // equals the haploid number, size of second dimension equals two (two chromosomes to form
    // deploid organism)
    // At this point, the next lines correspond to the size of each chromosome so populate the newly
    // created array
    // with this information. Stop reading when no more new lines or when a new header line is found
    BufferedReader genome_file_reader = new BufferedReader(new FileReader(genome_text_file));

    String line = null;
    StringBuilder organism_name;
    while ((line = genome_file_reader.readLine()) != null) {
      String[] split_line = line.split(" ");

      if (split_line[0].equals(">")) // If this is a first header line
      {
        organism_name =
            new StringBuilder()
                .append(split_line[1])
                .append(" ")
                .append(
                    split_line[
                        2]); // Recreate the genus and species of the organism from the strings that
        // were separated during the splitting of the line
        if (organism_name
            .toString()
            .equals(target_organism)) // If this line refers to the organism of interest
        {
          found_target_organism = true;
          haploid_number =
              Integer.parseInt(split_line[4]); // Get the haploid number stored in the header line
        } else {
          found_target_organism = false;
          continue; // This is a header line but it is not the organism of interest
        }
      } else if (found_target_organism
          && !end_of_genome) // This is not a header line and we probably want to import this line
      {
        // boolean autosome = true;
        switch (sex) {
          case 1: // Female
            {
              if (split_line[0].equals("chrX")) {
                temp_genome_data.add(split_line[1] + "," + split_line[1]);
              } else if (split_line[0].equals("chrY")) {
                end_of_genome = true;
              } // Ignore the Y chromosome
              else
                temp_genome_data.add(
                    split_line[1] + "," + split_line[1]); // The current line is an autosome
            }
            break;
          case 2: // Male
            {
              if (split_line[0].equals("chrX")) {
                temp_genome_data.add(split_line[1] + ",");
              } else if (split_line[0].equals("chrY")) {
                String temp =
                    temp_genome_data.get(
                        temp_genome_data.size() - 1); // Store the value already there
                temp_genome_data.remove(temp_genome_data.size() - 1);

                temp = temp + split_line[1];
                temp_genome_data.add(temp);

                end_of_genome = true;
              } else
                temp_genome_data.add(
                    split_line[1] + "," + split_line[1]); // The current line is an autosome
            }
            break;
        }
      }
    } // while ((line = genome_file_reader.readLine()) != null)
    genome_file_reader.close();
    return temp_genome_data;
  } // importGenomeData
Beispiel #13
0
  public boolean SaveDefaultCfg() {

    StringBuilder str = new StringBuilder();
    str.append("To jest zbior konfiguracyjny do wyliczen linii paskowej niesymetrycznej\n");
    str.append(MakeBackCompatibleForStorage(w));
    str.append("\n");
    str.append(MakeBackCompatibleForStorage(h));
    str.append("\n");
    str.append(MakeBackCompatibleForStorage(er));
    str.append("\n");
    str.append(MakeBackCompatibleForStorage(t));
    str.append("\n");

    return ShortTxtFile.EasyWrite(FName, str.toString());
  }