public Platform(Enviroment enviroment, ControlPolicy.ControlPolicyAbstract controller, CommunicationModel commModel)
 {
     Pose = new Pose();
     Map  = new MapObject(enviroment.Map.Rows, enviroment.Map.Columns);
     enviroment.Platforms.Add(this);
     this.enviroment         = enviroment;
     FieldOfViewRadius       = 2;
     this.ControlPolicy      = controller;
     this.CommunicationModel = commModel;
     IDs++;
     this.ID    = IDs;
     this.Color = Color.Blue;
 }
        private void setAllPlatformsAndSave(ControlPolicy.ControlPolicyAbstract policy, CommunicationModel comm, String path, String fileWithoutExtension)
        {
            String cpPrefix = "";

            foreach (Platform plt in enviroment.Platforms)
            {
                if (policy is ClosestFronterierControlPolicy)
                {
                    plt.ControlPolicy = new ClosestFronterierControlPolicy();
                    cpPrefix          = "cf";
                }

                if (policy is MaxInformationGainControlPolicy)
                {
                    plt.ControlPolicy = new MaxInformationGainControlPolicy();
                    cpPrefix          = "mi";
                }

                if (policy is BidingControlPolicy)
                {
                    plt.ControlPolicy = new BidingControlPolicy();
                    cpPrefix          = "bf";
                }
            }

            String commPrefix = "";

            foreach (Platform plt in enviroment.Platforms)
            {
                if (comm is NearbyCommunicationModel)
                {
                    plt.CommunicationModel = new NearbyCommunicationModel();
                    commPrefix             = "nc";
                }

                if (comm is GlobalCommunicationModel)
                {
                    plt.CommunicationModel = new GlobalCommunicationModel();
                    commPrefix             = "gc";
                }
            }


            String          newEnviromentPath = path + "//" + fileWithoutExtension + "_" + commPrefix + "_" + cpPrefix + ".bin";
            Stream          stream            = new FileStream(newEnviromentPath, FileMode.Create, FileAccess.Write, FileShare.None);
            BinaryFormatter binaryFormatter   = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();

            binaryFormatter.Serialize(stream, this.enviroment);
            stream.Close();
        }
Example #3
0
        public Bitmap Draw(MapObject map, List <Platform> platforms, Platform platform = null)
        {
            Bitmap   bitmap = new Bitmap(map.Columns * BinSize, map.Rows * BinSize);
            Graphics g      = Graphics.FromImage(bitmap);

            Pen blackPen    = new Pen(Color.Black, 1);
            Pen platformPen = new Pen(ColorPlatform, 1);

            //Color customColor = Color.FromArgb(50, Color.Gray);
            //SolidBrush shadowBrush = new SolidBrush(customColor);

            // draw map structure
            for (int i = 0; i < map.Rows; i++)
            {
                for (int j = 0; j < map.Columns; j++)
                {
                    Rectangle rect = new Rectangle(StartX + j * BinSize, StartY + i * BinSize, BinSize, BinSize);

                    // frame for boxes
                    int        val   = 255 - (int)(map.MapMatrix[i, j] * 255);
                    SolidBrush brush = new SolidBrush(Color.FromArgb(val, val, val));
                    g.FillRectangles(brush, new Rectangle[] { rect });
                    //g.DrawRectangle(blackPen, rect);

                    // draw distance map if it is applicable
                    if ((this.ShowDistanceMap) && (platform != null) && (platform.ControlPolicy is IDistanceMap))
                    {
                        IDistanceMap policy = platform.ControlPolicy as IDistanceMap;
                        double[,] distMap = policy.DistMap;
                        if (distMap != null)
                        {
                            if ((distMap[i, j] != Double.NegativeInfinity) && (distMap[i, j] != Double.PositiveInfinity))
                            {
                                double minDistMap = policy.MinDistMap - 1;
                                double maxDistMap = policy.MaxDistMap + 1;
                                if (maxDistMap != minDistMap)
                                {
                                    int val_map = (int)((distMap[i, j] - minDistMap) / (maxDistMap - minDistMap) * 100 + 1);

                                    brush = new SolidBrush(Color.FromArgb(255 - val_map, 0, 0));
                                    g.FillRectangles(brush, new Rectangle[] { rect });
                                }
                            }
                        }
                    }
                }
            }


            // draw platform spcific info
            if ((this.ShowBreadCumbers) && (platform != null))
            {
                ControlPolicy.ControlPolicyAbstract policy = platform.ControlPolicy;
                if (policy.Trajectory != null)
                {
                    foreach (Pose p in policy.Trajectory)
                    {
                        Rectangle rect = new Rectangle(StartX + p.Y * BinSize, StartY + p.X * BinSize, BinSize, BinSize);
                        g.FillRectangles(new SolidBrush(Color.Yellow), new Rectangle[] { rect });
                    }
                }

                if (policy.CommandSequence != null)
                {
                    foreach (Pose p in policy.CommandSequence)
                    {
                        Rectangle rect = new Rectangle(StartX + p.Y * BinSize, StartY + p.X * BinSize, BinSize, BinSize);
                        g.FillRectangles(new SolidBrush(Color.Orange), new Rectangle[] { rect });
                    }
                }

                if (policy.BestFronterier != null)
                {
                    Rectangle minPoseRect = new Rectangle(StartX + policy.BestFronterier.Y * BinSize, StartY + policy.BestFronterier.X * BinSize, BinSize, BinSize);
                    g.FillRectangles(new SolidBrush(Color.Orange), new Rectangle[] { minPoseRect });
                }
            }

            //draw platforms
            if (platforms != null)
            {
                foreach (Platform p in platforms)
                {
                    drawPlatform(g, p);
                }
            }

            if (platform != null)
            {
                drawPlatform(g, platform);
            }


            if ((platform != null) && (platform.ControlPolicy is IAllocationMap))
            {
                IAllocationMap policy = platform.ControlPolicy as IAllocationMap;
                if (policy.AllocationMap != null)
                {
                    for (int i = 0; i < map.Rows; i++)
                    {
                        for (int j = 0; j < map.Columns; j++)
                        {
                            if (policy.AllocationMap[i, j] == platform.ID)
                            {
                                Rectangle rect = new Rectangle(StartX + j * BinSize, StartY + i * BinSize, BinSize, BinSize);
                                g.DrawRectangle(platformPen, rect);
                            }
                        }
                    }
                }
            }

            // frame around the map to show extents
            blackPen = new Pen(Color.Black, 2);
            g.DrawRectangle(blackPen, StartX, StartY, map.Columns * BinSize, map.Rows * BinSize);

            return(bitmap);
        }