public void initPopulation(AbstractEnvironmentType env) { //_popsize = popsize; int init_error_threshold = 5; int init_error_count = 0; for (int i = 0; i < PhysaSetting._popsize; i++) { Amoeba newAmo = new Amoeba(_current_id); Point3d birthPlace = env.getRandomBirthPlace(util); if (!newAmo.initializeAmoeba(birthPlace.X, birthPlace.Y, birthPlace.Z, 4, env, util)) { init_error_count++; if (init_error_count > init_error_threshold) { break; } continue; } if (initOrient.Length > 0) { newAmo.orientation = initOrient; } population.Add(newAmo); _current_id++; } env._escape_p = PhysaSetting.escape_p; }
public void birthNew(Amoeba agent, AbstractEnvironmentType env) { //if (agent.curx <= 4 || agent.curx >= env.u - 4 || agent.cury <= 4 || agent.cury >= env.v - 4 || agent.curz <= 4 || agent.curz >= env.w - 4) // return; if (env.isOutsideBorderRangeByIndex(agent.curx, agent.cury, agent.curz)) { return; } //if (agent.curx == agent.cury || agent.curx == agent.curz) // return; Point3d newPos = env.getNeighbourhoodFreePosByIndex(agent.curx, agent.cury, agent.curz, 1, util); if (newPos.X == -1 || newPos.Y == -1 || newPos.Y == -1) { return; } _current_id++; int thisindex = _current_id - 1; Amoeba newAmo = new Amoeba(thisindex); newAmo.initializeAmoeba(newPos.X, newPos.Y, newPos.Z, env, util); newAmo.prev_loc = agent.Location; //newAmo.initializeAmoeba(agent.curx, agent.cury, agent.curz, 2, _grid, util); newAmo.selectRandomDirection(env, util, agent.orientation); //Amoeba newAmo = new Amoeba(_current_population - 1, _sense_angle, _rotate_angle, _sense_offset, _detectDir, _death_distance, _speed, _pcd, _depT); //Point3d birthPlace = _grid.getRandomBirthPlace(util); //newAmo.initializeAmoeba((int) birthPlace.X, (int) birthPlace.Y, (int) birthPlace.Z, 3, _grid, util); //newAmo._guide_factor = guide_factor; _toborn_population.Add(newAmo); }