Ejemplo n.º 1
0
        private void toolStripMenuItemTask_Click(object sender, EventArgs e)
        {
            FormProblem dialog = new FormProblem();

            dialog.TargetFunctionIndex = targetFunction.Index;
            dialog.NumConstraints      = constraints.Count;
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                targetFunction = new GrishaginFunction(dialog.TargetFunctionIndex);
                if (dialog.RegenerateConstraints || (dialog.NumConstraints != constraints.Count))
                {
                    constraints.Clear();
                    for (int i = 0; i < dialog.NumConstraints; i++)
                    {
                        GenerateConstraint();
                    }
                }

                ResetControls();

                toolStripMenuItemSolve.Enabled       = true;
                toolStripMenuItemMethod.Enabled      = true;
                toolStripMenuItemSaveResults.Enabled = false;
            }
            dialog.Dispose();
        }
Ejemplo n.º 2
0
        private void DrawOperationProperty(int index, Color color, PlotBuilder graph)
        {
            int[] indices       = new int[100];
            int[] numIterations = new int[100];

            for (int i = 0; i < 100; i++)
            {
                indices[i] = i;
            }

            Cursor = Cursors.WaitCursor;
            for (int i = 0; i < 100; i++)
            {
                Problem problem = new Problem();
                problem.Left        = new double[] { 0.0, 0.0 };
                problem.Right       = new double[] { 1.0, 1.0 };
                problem.Constraints = new List <FunctionDelegate>();

                GrishaginFunction targetFunction = new GrishaginFunction(i + 1);
                problem.TargetFunction = delegate(double[] args)
                {
                    return(-targetFunction.CalculateFunction(args));
                };

                method = (Method)Activator.CreateInstance(methods[experiments[index].MethodName]);
                method.SetProblem(problem);
                method.SetOptions(experiments[index].MethodOptions);
                method.IsOperationProperty = true;
                method.MaximumPoint        = targetFunction.MaximumPoint;
                method.Solve();
                Text = "Выполнено: " + i + "%";

                numIterations[i] = method.GetTrials().Count;
            }
            Cursor = Cursors.Default;
            Text   = "OptimLab";

            Array.Sort(numIterations, indices);

            PointF[] points = new PointF[100];
            for (int i = 0; i < 100; i++)
            {
                points[i] = new PointF(numIterations[i], i + 1);
            }

            Plot plotPoints = Triangulator.PointsVertexArray(points);

            plotPoints.Information.Name = "Points" + index;
            plotPoints.Color            = color;
            graph.AddPlot(plotPoints);

            Plot plotLines = Triangulator.CurveStripVertexArray(points);

            plotLines.Information.Name = "Lines" + index;
            plotLines.Color            = color;
            graph.AddPlot(plotLines);
        }
Ejemplo n.º 3
0
        public FormMain()
        {
            InitializeComponent();
            MinimumSize = new Size(640, 480);

            methods     = new Dictionary <string, Type>();
            experiments = new List <Experiment>();

            FileInfo[] files = new DirectoryInfo(Application.StartupPath).GetFiles();

            foreach (FileInfo file in files)
            {
                try
                {
                    Assembly assembly = Assembly.LoadFile(file.FullName);
                    Type[]   types    = assembly.GetTypes();

                    foreach (Type type in types)
                    {
                        if (type.IsSubclassOf(typeof(Method)) && !methods.ContainsKey(type.Name))
                        {
                            methods.Add(type.Name, type);
                        }
                    }
                }
                catch (BadImageFormatException ex)
                {
                }
            }

            Dictionary <string, ToolStripMenuItem> menuItemGroups = new Dictionary <string, ToolStripMenuItem>();

            foreach (Type type in methods.Values)
            {
                string groupName = ((Method)Activator.CreateInstance(type)).GetGroupName();

                if (!menuItemGroups.ContainsKey(groupName))
                {
                    ToolStripMenuItem menuItemGroup = new ToolStripMenuItem();
                    menuItemGroup.Name = "toolStripMenuItemGroup" + groupName;
                    menuItemGroup.Text = groupName;
                    menuItemGroups.Add(groupName, menuItemGroup);
                }
            }

            bool isFirstMethod = true;

            foreach (String methodName in methods.Keys)
            {
                ToolStripMenuItem menuItem = new ToolStripMenuItem();
                menuItem.Name   = "toolStripMenuItem" + methodName;
                menuItem.Text   = ((Method)Activator.CreateInstance(methods[methodName])).GetMethodName();
                menuItem.Click += new EventHandler(toolStripMenuItemAnyMethod_Click);

                if (isFirstMethod)
                {
                    menuItemCurrentMethod = menuItem;
                    menuItemCurrentMethod.PerformClick();
                    isFirstMethod = false;
                }

                string groupName = ((Method)Activator.CreateInstance(methods[methodName])).GetGroupName();
                menuItemGroups[groupName].DropDownItems.Add(menuItem);
            }

            int currentPosition = 0;

            foreach (ToolStripMenuItem menuItem in menuItemGroups.Values)
            {
                toolStripMenuItemMethod.DropDownItems.Insert(currentPosition, menuItem);
                currentPosition++;
            }

            targetFunction = new GrishaginFunction(1);
            constraints    = new List <Constraint>();

            plotBuilder             = new PlotBuilder();
            plotBuilder.ShowAxises  = false;
            plotBuilder.ShowNumbers = false;
            SetSizesAndLocations();
            Controls.Add(plotBuilder);
            ResetControls();
        }
Ejemplo n.º 4
0
        private void toolStripMenuItemOpenResults_Click(object sender, EventArgs e)
        {
            FormOpenResults dialog = new FormOpenResults();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                StreamReader file = new StreamReader(dialog.FileName);
                string       temp = "";

                temp           = file.ReadLine();
                targetFunction = new GrishaginFunction(Int32.Parse(temp));

                constraints.Clear();
                temp = file.ReadLine();
                int numConstraints = Int32.Parse(temp);
                for (int i = 0; i < numConstraints; i++)
                {
                    temp = file.ReadLine();
                    string[]   numbers    = temp.Split(' ');
                    Constraint constraint = new Constraint();
                    constraint.A = Double.Parse(numbers[0]);
                    constraint.B = Double.Parse(numbers[1]);
                    constraint.F = new GrishaginFunction(Int32.Parse(numbers[2]));
                    constraints.Add(constraint);
                }

                ResetControls();

                temp = file.ReadLine();
                int numPoints = Int32.Parse(temp);

                PointF[] points  = new PointF[numPoints];
                int[]    indices = new int[numPoints];
                for (int i = 0; i < numPoints; i++)
                {
                    temp = file.ReadLine();
                    string[] numbers = temp.Split(' ');
                    points[i] = new PointF(Single.Parse(numbers[1], CultureInfo.InvariantCulture),
                                           Single.Parse(numbers[2], CultureInfo.InvariantCulture));
                    indices[i] = Int32.Parse(numbers[3]);
                }

                int partSize = numPoints;
                if (dialog.ShowMode == ShowMode.Partial)
                {
                    partSize = dialog.PartSize;
                }
                if (partSize > numPoints)
                {
                    partSize = numPoints;
                }

                labelIterations.Text = OptimLab.Properties.Resources.LabelIterationsText + ": " + numPoints;

                int shownPoints = 0;
                while (shownPoints < numPoints)
                {
                    int currPartSize = Math.Min(partSize, numPoints - shownPoints);
                    for (int i = 0; i < currPartSize; i++)
                    {
                        Plot plot = Triangulator.PointsVertexArray(new PointF[] { points[shownPoints] });
                        plot.Information.Name = "TP" + shownPoints;
                        if (indices[shownPoints] == constraints.Count)
                        {
                            plot.Color = Color.Blue;
                        }
                        else
                        {
                            plot.Color = Color.Black;
                        }
                        plotBuilder.AddPlot(plot);
                        shownPoints++;
                    }
                    Application.DoEvents();
                    Thread.Sleep(400);
                }

                toolStripMenuItemSolve.Enabled       = false;
                toolStripMenuItemMethod.Enabled      = false;
                toolStripMenuItemSaveResults.Enabled = false;
            }
            dialog.Dispose();
        }
Ejemplo n.º 5
0
 public Constraint(double A, double B, int I)
 {
     this.A = A;
     this.B = B;
     this.F = new GrishaginFunction(I);
 }