コード例 #1
0
        public bool initializeAmoeba(double x, double y, double z, int radius, AbstractEnvironmentType env, Libutility util)
        {
            int     try_count    = 0;
            Point3d IniIndexLoca = env.getIndexByPosition(x, y, z);
            int     start_x      = (int)IniIndexLoca.X - radius > 0 ? (int)IniIndexLoca.X - radius : 0;
            int     start_y      = (int)IniIndexLoca.Y - radius > 0 ? (int)IniIndexLoca.Y - radius : 0;
            int     start_z      = (int)IniIndexLoca.Z - radius > 0 ? (int)IniIndexLoca.Z - radius : 0;
            int     end_x        = (int)IniIndexLoca.X + radius < env.u ? (int)IniIndexLoca.X + radius : env.u - 1;
            int     end_y        = (int)IniIndexLoca.Y + radius < env.v ? (int)IniIndexLoca.Y + radius : env.v - 1;
            int     end_z        = (int)IniIndexLoca.Z + radius < env.w ? (int)IniIndexLoca.Z + radius : env.w - 1;

            do
            {
                tempx = util.getRand(start_x, end_x + 1);
                tempy = util.getRand(start_y, end_y + 1);
                tempz = util.getRand(start_z, end_z + 1);
                try_count++;
            }while (!iniSuccess(tempx, tempy, tempz, env, util) && try_count < 10);
            curx = tempx;
            cury = tempy;
            curz = tempz;
            //Location = new Point3d(curx, cury, curz);
            Location = env.getPositionByIndex(curx, cury, curz);
            occupyCell(curx, cury, curz, env);
            selectRandomDirection(env, util);
            prev_loc = new Point3d(x, y, z);
            return(true);
        }
コード例 #2
0
ファイル: Physarum.cs プロジェクト: ys9789/Physarealm
        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;
        }
コード例 #3
0
ファイル: SystemComponent.cs プロジェクト: lxfschr/Quelea
    protected override bool GetInputs(IGH_DataAccess da)
    {
      agents = new List<IQuelea>();
      emitters = new List<AbstractEmitterType>();
      environment = new WorldEnvironmentType();
      // Then we need to access the input parameters individually. 
      // When data cannot be extracted from a parameter, we should abort this
      // method.
      if (!da.GetDataList(nextInputIndex++, agents)) return false;
      if (!da.GetDataList(nextInputIndex++, emitters)) return false;
      da.GetData(nextInputIndex++, ref environment);

      // We should now validate the data and warn the user if invalid data is 
      // supplied.
      if (agents.Count <= 0)
      {
        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, RS.agentsCountErrorMessage);
        return false;
      }
      if (emitters.Count <= 0)
      {
        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, RS.emittersCountErrorMessage);
        return false;
      }
      return true;
    }
コード例 #4
0
ファイル: Physarum.cs プロジェクト: ys9789/Physarealm
        public void Update(AbstractEnvironmentType env)
        {
            updatePopulation(env);
            updateTrails(env);

            if (_step % PhysaSetting._death_frequency_test == 0)
            {
                doDeathTest(env);
            }
            if (_step % PhysaSetting._division_frequency_test == 0)
            {
                doDivisionTest(env);
            }
            foreach (Amoeba tb in _toborn_population)
            {
                population.Add(tb);
            }
            foreach (int tdid in _todie_id)
            {
                population.Remove(population.Where(a => a.ID == tdid).First());
            }
            _toborn_population = new List <Amoeba>();
            _todie_id          = new List <int>();
            _step++;
        }
コード例 #5
0
ファイル: Physarum.cs プロジェクト: ys9789/Physarealm
        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);
        }
コード例 #6
0
ファイル: Physarum.cs プロジェクト: ys9789/Physarealm
        public void doDivisionTest(AbstractEnvironmentType env)
        {
            //shuffleOrder();

            /*
             * System.Threading.Tasks.Parallel.ForEach(population, amo =>
             * {
             * if (amo._divide)
             * {
             * birthNew(amo);
             * //_current_population++;
             * }
             * amo._divide = false;
             * });*/

            foreach (Amoeba amo in population)
            {
                if (amo._divide == true)
                {
                    birthNew(amo, env);
                    _current_id++;
                    //_current_population++;
                }
                amo._divide = false;
            }
        }
コード例 #7
0
        public void doSensorBehaviorsInSrfenv(AbstractEnvironmentType env, Libutility util)
        {
            this.doDeathTest(env);
            int   det_count    = PhysaSetting.DetectDirPhySubd * 2 + 1;
            int   max_item     = 0;
            float max_item_phy = -PhysaSetting._sense_angle;

            sensor_data = new float[det_count];
            //List<trailInfo> infos = new List<trailInfo>();
            //infos.Add(env.getOffsetTrailValue(curx, cury, curz, orientation, 0, 0, _sensor_offset, util));
            //float maxtrail = 0;
            //Point3d tgtPos = new Point3d();
            //sensor_data[0] = env.getOffsetTrailValue(curx, cury, curz, orientation, 0, 0, PhysaSetting._sense_offset, util);
            int count_cur = 0;

            for (int j = -PhysaSetting.DetectDirPhySubd; j <= PhysaSetting.DetectDirPhySubd; j++)
            {
                sensor_data[count_cur] = env.getOffsetTrailValue(curx, cury, curz, uv_orientation, j * PhysaSetting._sensor_phy_step_angle, 0, PhysaSetting._sense_offset, util);
                //infos.Add(env.getOffsetTrailValue(curx, cury, curz, orientation, j * _sensor_phy_step_angle, i * _sensor_theta_step_angle, _sensor_offset, util));
                if (sensor_data[count_cur] > sensor_data[max_item])
                {
                    max_item     = count_cur;
                    max_item_phy = j * PhysaSetting._sensor_phy_step_angle;
                }
                count_cur++;
            }
            //this.tempValue = env.getOffsetTrailValue(curx, cury, curz, uv_orientation, 0, 0, PhysaSetting._sense_offset, util);
            //max_item_phy = 90;
            rotate2D(max_item_phy * PhysaSetting._rotate_angle / PhysaSetting._sense_angle);
            orientation = env.getOrientationFromUv(Location, uv_orientation);
            guideOrientation();
        }
コード例 #8
0
 public void selectRandomDirection(AbstractEnvironmentType env, Libutility util, Vector3d preDir)
 {
     if (env.env_type == 1)
     {
         double   randx   = (util.getRandDouble() - 0.5) * 2;
         double   randy   = (util.getRandDouble() - 0.5) * 2;
         double   randz   = (util.getRandDouble() - 0.5) * 2;
         Vector3d randDir = new Vector3d(randx, randy, randz);
         randDir = Vector3d.Add(randDir, preDir);
         Double leng   = randDir.Length;
         Double factor = _cur_speed / leng;
         orientation = Vector3d.Multiply(factor, randDir);
         return;
     }
     else if (env.env_type == 2)
     {
         double   randx   = (util.getRandDouble() - 0.5) * 2;
         double   randy   = (util.getRandDouble() - 0.5) * 2;
         Vector3d randDir = new Vector3d(randx, randy, 0);
         randDir = Vector3d.Add(randDir, preDir);
         randDir.Unitize();
         uv_orientation = Vector3d.Multiply(_cur_speed, randDir);
         orientation    = env.getOrientationFromUv(Location, uv_orientation);
         return;
     }
 }
コード例 #9
0
ファイル: Physarum.cs プロジェクト: ys9789/Physarealm
        public void doDeathTest(AbstractEnvironmentType env)
        {
            //shuffleOrder();

            /*
             * System.Threading.Tasks.Parallel.ForEach(population, amo =>
             * {
             * if (amo._die )
             * {
             * _grid.clearGridCellByIndex(amo.curx, amo.cury, amo.curz);
             * _todie_population.Add(amo);
             * //population.Remove(amo);
             * _current_population--;
             * }
             * });
             */

            foreach (Amoeba amo in population)
            {
                if (amo._die)
                {
                    env.clearGridCellByIndex(amo.curx, amo.cury, amo.curz);
                    _todie_id.Add(amo.ID);
                    //population.Remove(amo);
                    //_current_population--;
                }
            }
        }
コード例 #10
0
ファイル: AbstractSystemType.cs プロジェクト: vctcn93/Quelea
 protected AbstractSystemType(AbstractSystemType <T> system)
 {
     // private ISpatialCollection<AgentType> agents;
     queleaSettings = system.queleaSettings;
     emitters       = system.emitters;
     environment    = system.environment;
     UpdateBounds();
     Quelea = new SpatialCollectionAsBinLattice <T>(min, max, (int)(Number.Clamp((min.DistanceTo(max) / 5), 5, 25)), (IList <T>)system.Quelea.SpatialObjects);
 }
コード例 #11
0
 public void resetFloatingPointPosition(AbstractEnvironmentType env)
 {
     Location = env.getPositionByIndex(curx, cury, curz);
     //tempfloatx = curx;
     //tempfloaty = cury;
     //tempfloatz = curz;
     //Location = new Point3d(curx, cury, curz);
     return;
 }
コード例 #12
0
ファイル: AbstractSystemType.cs プロジェクト: vctcn93/Quelea
 protected AbstractSystemType(T[] queleaSettings, AbstractEmitterType[] emitters, AbstractEnvironmentType environment, AbstractSystemType <T> system)
 {
     timestep            = system.timestep;
     nextIndex           = system.nextIndex;
     this.queleaSettings = queleaSettings;
     this.emitters       = emitters;
     this.environment    = environment;
     UpdateBounds();
     Quelea = new SpatialCollectionAsBinLattice <T>(min, max, (int)(Number.Clamp((min.DistanceTo(max) / 5), 5, 25)), (IList <T>)system.Quelea.SpatialObjects);
 }
コード例 #13
0
ファイル: AgentType.cs プロジェクト: lxfschr/Quelea
 public AgentType(IAgent a, Point3d emittionPt, Vector3d initialVelocity, AbstractEnvironmentType environment)
   : base(a, emittionPt, initialVelocity, environment)
 {
   SteerAcceleration = a.SteerAcceleration;
   MaxSpeed = a.MaxSpeed;
   MaxForce = a.MaxForce;
   VisionRadius = a.VisionRadius;
   VisionAngle = a.VisionAngle;
   Lat = 0;//Util.Random.RandomDouble(0, RS.TWO_PI);
   Lon = 0;//Util.Random.RandomDouble(-RS.HALF_PI, RS.HALF_PI);
 }
コード例 #14
0
 public void doDivisionTest(AbstractEnvironmentType env)
 {
     _divide = false;
     if (env.isOutsideBorderRangeByIndex(curx, cury, curz))
     {
         return;
     }
     if (isWithinBirthRange(curx, cury, curz, env))
     {
         _divide = true;
     }
 }
コード例 #15
0
 public bool iniSuccess(int x, int y, int z, AbstractEnvironmentType env, Libutility util)
 {
     if (env.isOccupidByParticleByIndex(x, y, z) == true)
     {
         return(false);
     }
     if (env.isWithinObstacleByIndex(x, y, z) && util.getRandDouble() > PhysaSetting.escape_p)
     {
         return(false);
     }
     return(true);
 }
コード例 #16
0
 public void occupyCell(int x, int y, int z, AbstractEnvironmentType env)
 {
     env.clearGridCellByIndex(curx, cury, curz);
     env.occupyGridCellByIndex(tempx, tempy, tempz, ID);
     curx = tempx;
     cury = tempy;
     curz = tempz;
     resetFloatingPointPosition(env);
     if (_moved_successfully)
     {
         env.increaseTrailByIndex(curx, cury, curz, _ca_torealease);
     }
 }
コード例 #17
0
        public void doSensorBehaviorsInBoxenv(AbstractEnvironmentType env, Libutility util)
        {
            this.doDeathTest(env);
            //orientation = env.projectOrientationToEnv(Location, orientation);
            int   det_count      = PhysaSetting.DetectDirRSubd * PhysaSetting.DetectDirPhySubd + 1;
            int   max_item       = 0;
            float max_item_phy   = 0;
            float max_item_theta = 0;

            sensor_data = new float[det_count];
            //List<trailInfo> infos = new List<trailInfo>();
            //infos.Add(env.getOffsetTrailValue(curx, cury, curz, orientation, 0, 0, _sensor_offset, util));
            //float maxtrail = 0;
            //Point3d tgtPos = new Point3d();
            sensor_data[0] = env.getOffsetTrailValue(curx, cury, curz, orientation, 0, 0, PhysaSetting._sense_offset, util);
            int count_cur = 1;

            for (int i = 0; i < PhysaSetting.DetectDirRSubd; i++)
            {
                for (int j = 1; j <= PhysaSetting.DetectDirPhySubd; j++)
                {
                    sensor_data[count_cur] = env.getOffsetTrailValue(curx, cury, curz, orientation, j * PhysaSetting._sensor_phy_step_angle, i * PhysaSetting._sensor_theta_step_angle, PhysaSetting._sense_offset, util);
                    //infos.Add(env.getOffsetTrailValue(curx, cury, curz, orientation, j * _sensor_phy_step_angle, i * _sensor_theta_step_angle, _sensor_offset, util));
                    if (sensor_data[count_cur] > sensor_data[max_item])
                    {
                        max_item       = count_cur;
                        max_item_phy   = j * PhysaSetting._sensor_phy_step_angle;
                        max_item_theta = i * PhysaSetting._sensor_theta_step_angle;
                    }
                    count_cur++;
                }
            }

            /*foreach(trailInfo inf in infos)
             * {
             * if(inf.trailValue > maxtrail)
             * {
             *  maxtrail = inf.trailValue;
             *  tgtPos = inf.targetPos;
             * }
             * }
             * Vector3d newOri = Point3d.Subtract(tgtPos, new Point3d(curx, cury, curz));
             * double curLength = newOri.Length;
             * double scaleFactor = _cur_speed / curLength;
             * orientation = Vector3d.Multiply(scaleFactor, newOri);
             * //orientation = newOri;
             */

            rotate(max_item_phy * PhysaSetting._rotate_angle / PhysaSetting._sense_angle, max_item_theta);
            guideOrientation();
        }
コード例 #18
0
 public void doDeathTest(AbstractEnvironmentType env)
 {
     _die = false;
     if (env.isOutsideBorderRangeByIndex(curx, cury, curz) && PhysaSetting.border_type != 2)
     {
         _die = true;
     }
     //if (env.envdata[curx, cury, curz] == 2)
     //  _die = true;
     //return;
     if (isOutsideSurvivalRange(curx, cury, curz, env))
     {
         _die = true;
     }
 }
コード例 #19
0
        public bool isWithinBirthRange(int x, int y, int z, AbstractEnvironmentType env)
        {
            int d = env.countNumberOfParticlesPresentByIndex(x, y, z, PhysaSetting.gw);

            //_around = d;
            tempValue = d;
            if (d >= PhysaSetting.gmin && d < PhysaSetting.gmax)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #20
0
        public bool isOutsideSurvivalRange(int x, int y, int z, AbstractEnvironmentType env)
        {
            if (_distance_traveled > PhysaSetting._death_distance)
            {
                return(true);
            }
            double d = env.countNumberOfParticlesPresentByIndex(x, y, z, PhysaSetting.sw);

            if (d < PhysaSetting.smin || d > PhysaSetting.smax)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #21
0
        public bool initializeAmoeba(double x, double y, double z, AbstractEnvironmentType env, Libutility util)
        {
            Point3d indexLoca = env.getIndexByPosition(x, y, z);

            tempx = (int)indexLoca.X;
            tempy = (int)indexLoca.Y;
            tempz = (int)indexLoca.Z;
            curx  = tempx;
            cury  = tempy;
            curz  = tempz;
            //Location = new Point3d(curx, cury, curz);
            Location = env.getPositionByIndex(curx, cury, curz);
            occupyCell(curx, cury, curz, env);
            selectRandomDirection(env, util);
            prev_loc = Location;
            return(true);
        }
コード例 #22
0
 public bool initializeAmoeba(AbstractEnvironmentType env, Libutility util)
 {
     do
     {
         tempfloatx = (float)util.getDoubleRand(env.getUMin(), env.getUMax());
         tempfloaty = (float)util.getDoubleRand(env.getVMin(), env.getVMax());
         tempfloatz = (float)util.getDoubleRand(env.getWMin(), env.getWMax());
         Point3d indexPos = env.getIndexByPosition(tempfloatx, tempfloaty, tempfloatz);
         tempx = (int)indexPos.X;
         tempy = (int)indexPos.Y;
         tempz = (int)indexPos.Z;
     }while (!iniSuccess(tempx, tempy, tempz, env, util));
     curx = tempx;
     cury = tempy;
     curz = tempz;
     //Location = new Point3d(curx, cury, curz);
     Location = env.getPositionByIndex(curx, cury, curz);
     occupyCell(curx, cury, curz, env);
     selectRandomDirection(env, util);
     prev_loc = Location;
     return(true);
 }
コード例 #23
0
ファイル: Physarum.cs プロジェクト: ys9789/Physarealm
        public void updatePopulation(AbstractEnvironmentType env)
        {
            foreach (Amoeba amo in population)
            {
                amo.doMotorBehaviors(env, util);
            }
            shuffleOrder();
            foreach (Amoeba amo in population)
            {
                amo.doSensorBehavior[env.env_type - 1].Invoke(env, util);
            }

            /*
             * System.Threading.Tasks.Parallel.ForEach(population, amo =>
             * {
             *  amo.doMotorBehaviors(env, util);
             * });
             * System.Threading.Tasks.Parallel.ForEach(population, amo =>
             * {
             *  amo.doSensorBehaviors(env, util);
             * });
             *///Parallel will be a little bit faster, but may encounter unexpected error that every agent freeze....so i disable
        }
コード例 #24
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public void resetFloatingPointPosition(AbstractEnvironmentType env)
 {
     Location = env.getPositionByIndex(curx, cury, curz);
     //tempfloatx = curx;
     //tempfloaty = cury;
     //tempfloatz = curz;
     //Location = new Point3d(curx, cury, curz);
     return;
 }
コード例 #25
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public void selectRandomDirection(AbstractEnvironmentType env, Libutility util, Vector3d preDir)
 {
     if (env.env_type == 1)
     {
         double randx = (util.getRandDouble() - 0.5) * 2;
         double randy = (util.getRandDouble() - 0.5) * 2;
         double randz = (util.getRandDouble() - 0.5) * 2;
         Vector3d randDir = new Vector3d(randx, randy, randz);
         randDir = Vector3d.Add(randDir, preDir);
         Double leng = randDir.Length;
         Double factor = _cur_speed / leng;
         orientation = Vector3d.Multiply(factor, randDir);
         return;
     }
     else if (env.env_type == 2)
     {
         double randx = (util.getRandDouble() - 0.5) * 2;
         double randy = (util.getRandDouble() - 0.5) * 2;
         Vector3d randDir = new Vector3d(randx, randy, 0);
         randDir = Vector3d.Add(randDir, preDir);
         randDir.Unitize();
         uv_orientation = Vector3d.Multiply(_cur_speed, randDir);
         orientation = env.getOrientationFromUv(Location, uv_orientation);
         return;
     }
 }
コード例 #26
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public bool isWithinBirthRange(int x, int y, int z, AbstractEnvironmentType env)
 {
     int d = env.countNumberOfParticlesPresentByIndex(x, y, z, PhysaSetting.gw);
     //_around = d;
     tempValue = d;
     if (d >= PhysaSetting.gmin && d < PhysaSetting.gmax)
         return true;
     else
         return false;
 }
コード例 #27
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public void occupyCell(int x, int y, int z, AbstractEnvironmentType env)
 {
     env.clearGridCellByIndex(curx, cury, curz);
     env.occupyGridCellByIndex(tempx, tempy, tempz, ID);
     curx = tempx;
     cury = tempy;
     curz = tempz;
     resetFloatingPointPosition(env);
     if (_moved_successfully)
         env.increaseTrailByIndex(curx, cury, curz, _ca_torealease);
 }
コード例 #28
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public bool initializeAmoeba(double x, double y, double z,  int radius, AbstractEnvironmentType env, Libutility util)
 {
     int try_count = 0;
     Point3d IniIndexLoca = env.getIndexByPosition(x, y, z);
     int start_x = (int)IniIndexLoca.X - radius > 0 ? (int)IniIndexLoca.X - radius : 0;
     int start_y = (int)IniIndexLoca.Y - radius > 0 ? (int)IniIndexLoca.Y - radius : 0;
     int start_z = (int)IniIndexLoca.Z - radius > 0 ? (int)IniIndexLoca.Z - radius : 0;
     int end_x = (int)IniIndexLoca.X + radius < env.u ? (int)IniIndexLoca.X + radius : env.u - 1;
     int end_y = (int)IniIndexLoca.Y + radius < env.v ? (int)IniIndexLoca.Y + radius : env.v - 1;
     int end_z = (int)IniIndexLoca.Z + radius < env.w ? (int)IniIndexLoca.Z + radius : env.w - 1;
     do
     {
         tempx = util.getRand(start_x, end_x + 1);
         tempy = util.getRand(start_y, end_y + 1);
         tempz = util.getRand(start_z, end_z + 1);
         try_count++;
     }
     while (!iniSuccess(tempx, tempy, tempz, env, util) && try_count<10);
     curx = tempx;
     cury = tempy;
     curz = tempz;
     //Location = new Point3d(curx, cury, curz);
     Location = env.getPositionByIndex(curx, cury, curz);
     occupyCell(curx, cury, curz, env);
     selectRandomDirection(env, util);
     prev_loc = new Point3d(x, y, z);
     return true;
 }
コード例 #29
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public bool isOutsideSurvivalRange(int x, int y, int z, AbstractEnvironmentType env)
 {
     if (_distance_traveled > PhysaSetting._death_distance)
     {
         return true;
     }
     double d = env.countNumberOfParticlesPresentByIndex(x, y, z, PhysaSetting.sw);
     if (d < PhysaSetting.smin || d > PhysaSetting.smax)
         return true;
     else return false;
 }
コード例 #30
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public bool initializeAmoeba(AbstractEnvironmentType env, Libutility util)
 {
     do
     {
         tempfloatx = (float)util.getDoubleRand(env.getUMin(), env.getUMax());
         tempfloaty = (float)util.getDoubleRand(env.getVMin(), env.getVMax());
         tempfloatz = (float)util.getDoubleRand(env.getWMin(), env.getWMax());
         Point3d indexPos = env.getIndexByPosition(tempfloatx, tempfloaty, tempfloatz);
         tempx = (int)indexPos.X;
         tempy = (int)indexPos.Y;
         tempz = (int)indexPos.Z;
     }
     while (!iniSuccess(tempx, tempy, tempz, env, util));
     curx = tempx;
     cury = tempy;
     curz = tempz;
     //Location = new Point3d(curx, cury, curz);
     Location = env.getPositionByIndex(curx, cury, curz);
     occupyCell(curx, cury, curz, env);
     selectRandomDirection(env, util);
     prev_loc = Location;
     return true;
 }
コード例 #31
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public void doDeathTest(AbstractEnvironmentType env)
 {
     _die = false;
     if (env.isOutsideBorderRangeByIndex(curx, cury, curz) && PhysaSetting.border_type != 2)
     {
         _die = true;
     }
     //if (env.envdata[curx, cury, curz] == 2)
     //  _die = true;
     //return;
     if (isOutsideSurvivalRange(curx, cury, curz, env))
         _die = true;
 }
コード例 #32
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public void doSensorBehaviorsInSrfenv(AbstractEnvironmentType env, Libutility util)
 {
     this.doDeathTest(env);
     int det_count = PhysaSetting.DetectDirPhySubd * 2 + 1;
     int max_item = 0;
     float max_item_phy = -PhysaSetting._sense_angle;
     sensor_data = new float[det_count];
     //List<trailInfo> infos = new List<trailInfo>();
     //infos.Add(env.getOffsetTrailValue(curx, cury, curz, orientation, 0, 0, _sensor_offset, util));
     //float maxtrail = 0;
     //Point3d tgtPos = new Point3d();
     //sensor_data[0] = env.getOffsetTrailValue(curx, cury, curz, orientation, 0, 0, PhysaSetting._sense_offset, util);
     int count_cur = 0;
     for (int j = -PhysaSetting.DetectDirPhySubd; j <= PhysaSetting.DetectDirPhySubd; j++)
         {
             sensor_data[count_cur] = env.getOffsetTrailValue(curx, cury, curz, uv_orientation, j * PhysaSetting._sensor_phy_step_angle,0, PhysaSetting._sense_offset, util);
             //infos.Add(env.getOffsetTrailValue(curx, cury, curz, orientation, j * _sensor_phy_step_angle, i * _sensor_theta_step_angle, _sensor_offset, util));
             if (sensor_data[count_cur] > sensor_data[max_item])
             {
                 max_item = count_cur;
                 max_item_phy = j * PhysaSetting._sensor_phy_step_angle;
             }
             count_cur++;
         }
     //this.tempValue = env.getOffsetTrailValue(curx, cury, curz, uv_orientation, 0, 0, PhysaSetting._sense_offset, util);
     //max_item_phy = 90;
     rotate2D(max_item_phy * PhysaSetting._rotate_angle / PhysaSetting._sense_angle);
     orientation = env.getOrientationFromUv(Location, uv_orientation);
     guideOrientation();
 }
コード例 #33
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public bool iniSuccess(int x, int y, int z, AbstractEnvironmentType env, Libutility util)
 {
     if (env.isOccupidByParticleByIndex(x, y, z) == true)
         return false;
     if (env.isWithinObstacleByIndex(x, y, z) && util.getRandDouble() > PhysaSetting.escape_p)
         return false;
     return true;
 }
コード例 #34
0
ファイル: Physarum.cs プロジェクト: ys9789/Physarealm
 public void updateTrails(AbstractEnvironmentType env)
 {
     env.projectToTrail();
     env.diffuseTrails();
 }
コード例 #35
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public void doMotorBehaviors(AbstractEnvironmentType env, Libutility util)
 {
     _distance_traveled++;
     prev_loc = Location;
     //_cur_speed = _max_speed * (1 - _distance_traveled / _deathDistance);
     _cur_speed = PhysaSetting._speed;
     if (env.getGriddataByIndex(curx, cury, curz) == 1)
         _distance_traveled = 0;
     _moved_successfully = false;
     if (util.getRandDouble() < PhysaSetting._pcd)
     {
       selectRandomDirection(env, util);
       resetFloatingPointPosition(env);
       return;
     }
     Point3d curLoc = Location;
     curLoc.Transform(Transform.Translation(orientation));
     //Location = curLoc;
     tempfloatx = (float)curLoc.X;
     tempfloaty = (float)curLoc.Y;
     tempfloatz = (float)curLoc.Z;
     switch (PhysaSetting.border_type)
     {
         case 0:
             if(env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz,0))
                 selectRandomDirection(env, util);
             break;
         case 1:
             env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 1);
             break;
         case 2:
             env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 0);
             orientation = env.bounceOrientation(curLoc, orientation);
             break;
         default:
             break;
     }
     //if(env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz))
     //    selectRandomDirection(util);
     Point3d temppos = env.getIndexByPosition(tempfloatx, tempfloaty, tempfloatz);
     tempx = (int)temppos.X;
     tempy = (int)temppos.Y;
     tempz = (int)temppos.Z;
     if (env.isOccupidByParticleByIndex(tempx, tempy, tempz))
     {
         selectRandomDirection(env,util);
         return;
     }
     else if (env.isWithinObstacleByIndex(tempx, tempy, tempz) && util.getRandDouble() > PhysaSetting.escape_p)
     {
         selectRandomDirection(env,util);
         return;
     }
     else
     {
         _moved_successfully = true;
         Location = env.projectLocationToEnv(new Point3d(tempfloatx, tempfloaty, tempfloatz));
         env.clearGridCellByIndex(curx, cury, curz);
         //env.agedata[curx, cury, curz]++;
         env.occupyGridCellByIndex(tempx, tempy, tempz, ID);
         curx = tempx;
         cury = tempy;
         curz = tempz;
         //float trailIncrement = calculateTrailIncrement(util);
         //env.increaseTrailByIndex(curx, cury, curz, trailIncrement);
         env.increaseTrailByIndex(curx, cury, curz, _ca_torealease);
         //if (_moved_successfully && !_die && _distance_traveled % division_frequency_test == 0)
         if (_moved_successfully && !_die)
             doDivisionTest(env);
     }
 }
コード例 #36
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public void doDivisionTest(AbstractEnvironmentType env)
 {
     _divide = false;
     if (env.isOutsideBorderRangeByIndex(curx, cury, curz))
         return;
     if (isWithinBirthRange(curx, cury, curz, env))
     {
         _divide = true;
     }
 }
コード例 #37
0
        public void doMotorBehaviors(AbstractEnvironmentType env, Libutility util)
        {
            _distance_traveled++;
            prev_loc = Location;
            //_cur_speed = _max_speed * (1 - _distance_traveled / _deathDistance);
            _cur_speed = PhysaSetting._speed;
            if (env.getGriddataByIndex(curx, cury, curz) == 1)
            {
                _distance_traveled = 0;
            }
            _moved_successfully = false;
            if (util.getRandDouble() < PhysaSetting._pcd)
            {
                selectRandomDirection(env, util);
                resetFloatingPointPosition(env);
                return;
            }
            Point3d curLoc = Location;

            curLoc.Transform(Transform.Translation(orientation));
            //Location = curLoc;
            tempfloatx = (float)curLoc.X;
            tempfloaty = (float)curLoc.Y;
            tempfloatz = (float)curLoc.Z;
            switch (PhysaSetting.border_type)
            {
            case 0:
                if (env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 0))
                {
                    selectRandomDirection(env, util);
                }
                break;

            case 1:
                env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 1);
                break;

            case 2:
                env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz, 0);
                orientation = env.bounceOrientation(curLoc, orientation);
                break;

            default:
                break;
            }
            //if(env.constrainPos(ref tempfloatx, ref tempfloaty, ref tempfloatz))
            //    selectRandomDirection(util);
            Point3d temppos = env.getIndexByPosition(tempfloatx, tempfloaty, tempfloatz);

            tempx = (int)temppos.X;
            tempy = (int)temppos.Y;
            tempz = (int)temppos.Z;
            if (env.isOccupidByParticleByIndex(tempx, tempy, tempz))
            {
                selectRandomDirection(env, util);
                return;
            }
            else if (env.isWithinObstacleByIndex(tempx, tempy, tempz) && util.getRandDouble() > PhysaSetting.escape_p)
            {
                selectRandomDirection(env, util);
                return;
            }
            else
            {
                _moved_successfully = true;
                Location            = env.projectLocationToEnv(new Point3d(tempfloatx, tempfloaty, tempfloatz));
                env.clearGridCellByIndex(curx, cury, curz);
                //env.agedata[curx, cury, curz]++;
                env.occupyGridCellByIndex(tempx, tempy, tempz, ID);
                curx = tempx;
                cury = tempy;
                curz = tempz;
                //float trailIncrement = calculateTrailIncrement(util);
                //env.increaseTrailByIndex(curx, cury, curz, trailIncrement);
                env.increaseTrailByIndex(curx, cury, curz, _ca_torealease);
                //if (_moved_successfully && !_die && _distance_traveled % division_frequency_test == 0)
                if (_moved_successfully && !_die)
                {
                    doDivisionTest(env);
                }
            }
        }
コード例 #38
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
 public bool initializeAmoeba(double x, double y, double z, AbstractEnvironmentType env, Libutility util)
 {
     Point3d indexLoca = env.getIndexByPosition(x, y, z);
     tempx = (int)indexLoca.X;
     tempy = (int)indexLoca.Y;
     tempz = (int)indexLoca.Z;
     curx = tempx;
     cury = tempy;
     curz = tempz;
     //Location = new Point3d(curx, cury, curz);
     Location = env.getPositionByIndex(curx, cury, curz);
     occupyCell(curx, cury, curz, env);
     selectRandomDirection(env, util);
     prev_loc = Location;
     return true;
 }
コード例 #39
0
ファイル: Amoeba.cs プロジェクト: maajor/Physarealm
        public void doSensorBehaviorsInBoxenv(AbstractEnvironmentType env, Libutility util)
        {
            this.doDeathTest(env);
            //orientation = env.projectOrientationToEnv(Location, orientation);
            int det_count = PhysaSetting.DetectDirRSubd * PhysaSetting.DetectDirPhySubd + 1;
            int max_item = 0;
            float max_item_phy = 0;
            float max_item_theta = 0;
            sensor_data = new float[det_count];
            //List<trailInfo> infos = new List<trailInfo>();
            //infos.Add(env.getOffsetTrailValue(curx, cury, curz, orientation, 0, 0, _sensor_offset, util));
            //float maxtrail = 0;
            //Point3d tgtPos = new Point3d();
            sensor_data[0] = env.getOffsetTrailValue(curx, cury, curz, orientation, 0, 0, PhysaSetting._sense_offset, util);
            int count_cur = 1;
            for (int i = 0; i < PhysaSetting.DetectDirRSubd; i++)
            {
                for (int j = 1; j <= PhysaSetting.DetectDirPhySubd; j++)
                {
                    sensor_data[count_cur] = env.getOffsetTrailValue(curx, cury, curz, orientation, j * PhysaSetting._sensor_phy_step_angle, i * PhysaSetting._sensor_theta_step_angle, PhysaSetting._sense_offset, util);
                    //infos.Add(env.getOffsetTrailValue(curx, cury, curz, orientation, j * _sensor_phy_step_angle, i * _sensor_theta_step_angle, _sensor_offset, util));
                    if (sensor_data[count_cur] > sensor_data[max_item])
                    {
                        max_item = count_cur;
                        max_item_phy = j * PhysaSetting._sensor_phy_step_angle;
                        max_item_theta = i * PhysaSetting._sensor_theta_step_angle;
                    }
                    count_cur++;
                }
            }
            /*foreach(trailInfo inf in infos)
            {
              if(inf.trailValue > maxtrail)
              {
                maxtrail = inf.trailValue;
                tgtPos = inf.targetPos;
              }
            }
            Vector3d newOri = Point3d.Subtract(tgtPos, new Point3d(curx, cury, curz));
            double curLength = newOri.Length;
            double scaleFactor = _cur_speed / curLength;
            orientation = Vector3d.Multiply(scaleFactor, newOri);
            //orientation = newOri;
            */

            rotate(max_item_phy * PhysaSetting._rotate_angle / PhysaSetting._sense_angle, max_item_theta);
            guideOrientation();
        }
コード例 #40
0
 /// <summary>
 /// Initializes a new instance of the EatBehaviorComponent class.
 /// </summary>
 protected AbstractEnvironmentalBehaviorComponent(string name, string nickname, string description,
                                                  Bitmap icon, string componentGuid)
   : base(name, nickname, description, icon, componentGuid)
 {
   environment = new AxisAlignedBoxEnvironmentType();
 }