public static Bitmap Draw(this VehicleRoutingSolution solution, BitmapStyle bitmapStyle = null)
        {
            BitmapStyle style   = bitmapStyle ?? new BitmapStyle();
            double      maxSize = Math.Max(solution.MaxWidth, solution.MaxHeight);
            double      scaleX  = (style.ImageWidth - style.MarginX - 8 * style.Radius) / maxSize;
            double      scaleY  = (style.ImageHeight - style.MarginY - 4 * style.Radius) / maxSize;

            PointF[][] points = new PointF[solution.NumberOfVehicles][];
            for (int i = 0; i < solution.NumberOfVehicles; i++)
            {
                int startInd = i * solution.VehicleCapacity;
                int endInd   = Math.Min((i + 1) * solution.VehicleCapacity, solution.NumberOfCustomers);
                points[i] = new PointF[endInd - startInd];
                for (int j = startInd; j < endInd; j++)
                {
                    int n = solution.Order[j];
                    points[i][j - startInd] = new PointF(style.MarginX + 2 * style.Radius + (float)(solution.X[n] * scaleX), style.ImageHeight - 2 * style.Radius - (float)(solution.Y[n] * scaleY));
                }
            }
            Bitmap bitmap = new Bitmap(style.ImageWidth, style.ImageHeight, PixelFormat.Format32bppRgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                Pen   pen        = new Pen(Color.FromName(style.PenColor), style.PenWidth);
                Brush brush      = new SolidBrush(Color.FromName(style.BrushColor));
                Brush penBrush   = new SolidBrush(Color.FromName(style.PenColor));
                Brush brushBlack = new SolidBrush(Color.Black);
                Font  font       = new Font(style.FontName, style.FontSize);
                Font  fontSmall  = new Font(style.FontName, style.FontSize - 2);
                g.Clear(Color.FromName(style.BackgroundColor));
                for (int i = 0; i < solution.NumberOfVehicles; i++)
                {
                    if (solution.IsFinal)
                    {
                        g.FillPolygon(brush, points[i]);
                    }
                    if (solution.OperatorTag != "init")
                    {
                        g.DrawPolygon(pen, points[i]);
                    }
                }
                for (int i = 0; i < solution.NumberOfVehicles; i++)
                {
                    for (int j = 0; j < points[i].Length; j++)
                    {
                        g.FillEllipse(brush, points[i][j].X - style.Radius, points[i][j].Y - style.Radius, 2 * style.Radius, 2 * style.Radius);
                        g.DrawEllipse(pen, points[i][j].X - style.Radius, points[i][j].Y - style.Radius, 2 * style.Radius, 2 * style.Radius);
                        g.DrawString(string.Format("{0}", solution.Order[i * solution.VehicleCapacity + j] + 1), fontSmall, penBrush, points[i][j].X, points[i][j].Y);
                    }
                }
                g.DrawString(String.Format("Tour lenght: {0:F4} (lower bound gap {1:F2}%){4}\nIterations: {2}\nTime: {3:F3}s", solution.TourLenght, solution.LowerBoundGap, solution.IterationNumber, solution.TimeInSeconds, solution.IsCurrentBest ? " <<<" : ""), font, brushBlack, 0, 0);
            }
            return(bitmap);
        }
예제 #2
0
 public BitmapStyle(BitmapStyle style)
 {
     ImageWidth      = style.ImageWidth;
     ImageHeight     = style.ImageHeight;
     MarginX         = style.MarginX;
     MarginY         = style.MarginY;
     FontName        = style.FontName;
     FontSize        = style.FontSize;
     PenColor        = style.PenColor;
     PenWidth        = style.PenWidth;
     BrushColor      = style.BrushColor;
     Radius          = style.Radius;
     BackgroundColor = style.BackgroundColor;
 }
        public static Bitmap Draw(this FloorplanSolution solution, BitmapStyle bitmapStyle = null)
        {
            BitmapStyle style = bitmapStyle ?? new BitmapStyle();

            double maxWidth  = solution.Transcoder % 2 == 0 ? solution.MaxWidth : solution.MaxHeight;
            double maxHeight = solution.Transcoder % 2 == 0 ? solution.MaxHeight : solution.MaxWidth;

            double[] X       = solution.Transcoder % 2 == 0 ? solution.X : solution.Y;
            double[] Y       = solution.Transcoder % 2 == 0 ? solution.Y : solution.X;
            double[] W       = solution.Transcoder % 2 == 0 ? solution.W : solution.H;
            double[] H       = solution.Transcoder % 2 == 0 ? solution.H : solution.W;
            double   maxSize = Math.Max(maxWidth, maxHeight);
            double   scaleX  = (style.ImageWidth - style.MarginX - 2 * style.PenWidth) / maxSize;
            double   scaleY  = (style.ImageHeight - style.MarginY - style.PenWidth) / maxSize;
            Bitmap   bitmap  = new Bitmap(style.ImageWidth, style.ImageHeight, PixelFormat.Format32bppRgb);

            using (Graphics g = Graphics.FromImage(bitmap))
            {
                Pen   pen        = new Pen(Color.FromName(style.PenColor), style.PenWidth);
                Brush brush      = new SolidBrush(Color.FromName(style.BrushColor));
                Brush penBrush   = new SolidBrush(Color.FromName(style.PenColor));
                Brush brushBlack = new SolidBrush(Color.Black);
                Font  font       = new Font(style.FontName, style.FontSize);
                Font  fontSmall  = new Font(style.FontName, style.FontSize - 2);
                g.Clear(Color.FromName(style.BackgroundColor));
                if (solution.IsFinal)
                {
                    g.FillRectangle(Brushes.LightGray, style.MarginX + style.PenWidth, bitmap.Height - style.PenWidth - (float)(maxHeight * scaleY), (float)(maxWidth * scaleX), (float)(maxHeight * scaleY));
                }
                for (int i = 0; i < solution.Order.Count; i++)
                {
                    int   n = solution.Order[i];
                    float x = style.MarginX + style.PenWidth + (float)((solution.Transcoder == 1 || solution.Transcoder == 2 ? maxWidth - X[n] - W[n] : X[n]) * scaleX);
                    float y = bitmap.Height - style.PenWidth - (float)((solution.Transcoder == 2 || solution.Transcoder == 3 ? maxHeight - Y[n] : Y[n] + H[n]) * scaleY);
                    float w = (float)(W[n] * scaleX);
                    float h = (float)(H[n] * scaleY);
                    g.FillRectangle(brush, x, y, w, h);
                    g.DrawRectangle(pen, x, y, w, h);
                    g.DrawString(string.Format("{0}", n), fontSmall, penBrush, x + w / 2 - style.FontSize, y + h / 2 - style.FontSize);
                }
                string summary = String.Format("Packing {5}: {0:F4} (utilization {1:F2}%){4}\nIterations: {2}\nTime: {3:F3}s", solution.CostValue, solution.Utilization, solution.IterationNumber, solution.TimeInSeconds, solution.IsCurrentBest ? " <<<" : "", solution.CostValue == maxWidth * maxHeight ? "area" : "cost");
                g.DrawString(summary, font, brushBlack, 0, 0);
            }
            return(bitmap);
        }
예제 #4
0
        public LocalSearchForm()
        {
            solutionStyle = new BitmapStyle(style);
            costStyle     = new BitmapStyle(style);

            bwTsp.DoWork             += new DoWorkEventHandler(bwTsp_DoWork);
            bwTsp.ProgressChanged    += new ProgressChangedEventHandler(bwTsp_ProgressChanged);
            bwTsp.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

            bwVehicleRouting.DoWork             += new DoWorkEventHandler(bwVehicleRouting_DoWork);
            bwVehicleRouting.ProgressChanged    += new ProgressChangedEventHandler(bwVehicleRouting_ProgressChanged);
            bwVehicleRouting.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

            bwFloorplan.DoWork             += new DoWorkEventHandler(bwFloorplan_DoWork);
            bwFloorplan.ProgressChanged    += new ProgressChangedEventHandler(bwFloorplan_ProgressChanged);
            bwFloorplan.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

            InitializeComponent();

            GetInitialSolutions();
        }