Beispiel #1
0
        public IActionResult Fletcher()
        {
            SolvedModel model    = new SolvedModel();
            int         nNumVars = 2;

            double[] fX = new double[] { 0, 0 };
            model.Start = new List <double>(fX);
            double[]     fParam   = new double[] { 0, 0 };
            int          nIter    = 0;     // contador de iteraciones
            int          nMaxIter = 100;   // limite de iteraciones
            double       fEpsFx   = 0.001; // Toleracion
            int          i;
            double       fBestF;           // Maximo
            string       sErrorMsg = "";
            Fletcher     oOpt;
            MyFxDelegate MyFx = new MyFxDelegate(Fx3);

            oOpt            = new Fletcher();
            model.Tolerace  = fEpsFx;
            model.MaxCycles = nMaxIter;
            fBestF          = oOpt.CalcOptim(nNumVars, ref fX, ref fParam, fEpsFx, nMaxIter, ref nIter, ref sErrorMsg, MyFx);
            if (sErrorMsg.Length > 0)
            {
                model.ErrorMsg = sErrorMsg;
            }
            for (i = 0; i < nNumVars; i++)
            {
                model.X.Add(fX[i]);
            }
            model.Function   = fBestF;
            model.Iterations = nIter;
            return(View(model));
        }
Beispiel #2
0
        public LinearResultWindow(SolvedModel model)
        {
            InitializeComponent();
            Model = model;

            Grid.Loaded += Grid_Loaded;
        }
Beispiel #3
0
        public IActionResult Hookes()
        {
            int nNumVars = 2;

            double[]      fX           = new double[] { 0, 0 };
            double[]      fParam       = new double[] { 0, 0 };
            double[]      fStepSize    = new double[] { 0.1, 0.1 };
            double[]      fMinStepSize = new double[] { 0.0000001, 0.0000001 };
            int           nIter        = 0;
            double        fEpsFx       = 0.01;
            int           i;
            object        fBestF;
            Hookes        oOpt;
            SolvedModel   model = new SolvedModel();
            MyFxDelegate  MyFx  = new MyFxDelegate(Fx3);
            SayFxDelegate SayFx = new SayFxDelegate(SayFx3);

            oOpt = new Hookes();

            model.Tolerace = fEpsFx;


            Console.WriteLine("******** FINAL RESULTS *************");
            fBestF = oOpt.CalcOptim(nNumVars, ref fX, ref fParam, ref fStepSize, ref fMinStepSize, fEpsFx, ref nIter, MyFx);
            Console.WriteLine("Optimum at");

            for (i = 0; i < nNumVars; i++)
            {
                model.X.Add(fX[i]);
            }
            model.Function   = (double)fBestF;
            model.Iterations = nIter;

            return(View(model));
        }
    //Run simplex algorithm starting from an initial SolverIteration
    public static SolvedModel Simplex(SolverIteration initialIteration, List <Constraint> constraints)
    {
        var             listIterations   = new List <SolverIteration>(new [] { initialIteration });
        SolverIteration currentIteration = initialIteration;

        while (true)
        {
            if (currentIteration.DecisionVariables.All(dv => dv >= 0))
            {
                var model = new SolvedModel
                {
                    SimplexIterations = listIterations,
                    Constraints       = constraints.ToList(),
                    Variables         = currentIteration.Variables.ToList(),
                    Z = currentIteration.Z
                };

                //Initialize dir for all vars
                foreach (var variable in currentIteration.Variables)
                {
                    model.ObjectiveResult[variable] = BigRational.Zero;
                }

                for (int i = 0; i < currentIteration.Bases.Length; i++)
                {
                    model.ObjectiveResult[currentIteration.Bases[i]] = currentIteration.BaseVariables[i];
                }

                model.Result =
                    constraints.All(c => ConstraintPasses(c, model.ObjectiveResult)) ?
                    SolvedResult.Optimized :
                    SolvedResult.Infeasible;

                return(model);
            }

            try
            {
                currentIteration = ComputeIteration(currentIteration);
                listIterations.Add(currentIteration);
            }
            catch (UnboundedException)
            {
                return(new SolvedModel
                {
                    Variables = initialIteration.Variables.ToList(),
                    Constraints = constraints.ToList(),
                    SimplexIterations = listIterations,
                    Result = SolvedResult.Unbounded
                });
            }
        }
    }
        public SolvedView(WindowBase owner, SolvedModel model)
        {
            Owner = owner;
            InitializeComponent();
#if DEBUG
            this.AttachDevTools();
#endif
            DataContextChanged += (sender, args) =>
            {
                var viewModel = DataContext as SolvedViewModel;
                viewModel.Model               = model;
                viewModel.Resources           = Resources;
                viewModel.MainWindow          = this;
                viewModel.PreviousPageCommand = ReactiveCommand.Create(viewModel.PreviousPage);
                viewModel.NextPageCommand     = ReactiveCommand.CreateFromTask(viewModel.NextPage);
                viewModel.Grid          = this.FindControl <Grid>("Grid");
                viewModel.BackButton    = this.FindControl <Button>("BackButton");
                viewModel.ForwardButton = this.FindControl <Button>("ForwardButton");
                var twoPhasesPages = viewModel.Model.TwoPhasesIterations
                                     .Select(i => new SolvedViewModel.SolverIterationPage
                {
                    Iteration = i, Method = SolvedViewModel.SolverMethod.TwoPhases
                });

                var simplexPages = viewModel.Model.SimplexIterations
                                   .Select(i => new SolvedViewModel.SolverIterationPage
                {
                    Iteration = i, Method = SolvedViewModel.SolverMethod.Simplex
                });

                viewModel.SolverIterationPages = twoPhasesPages.Concat(simplexPages).ToList();
                viewModel.BuildGrid(viewModel.SolverIterationPages[0].Iteration);
                viewModel.CurrentPageIndex = 0;
                viewModel.LoadPage(viewModel.CurrentPageIndex);
            };
        }
Beispiel #6
0
 public LinearResultWindow()
 {
     InitializeComponent();
     Model        = BuildSolvedModel();
     Grid.Loaded += Grid_Loaded;
 }