Exemple #1
0
        private void GenerateImageForSolution(LPsolveSolution solution)
        {
            // apply solution settings

            for (int i = 0; i < solution.Names.Count; i++)
            {
                if (!reactionTextTable.ContainsKey(solution.Names[i]))
                    continue;

                var label = (TempLabel) reactionTextTable[solution.Names[i]];
                for (int j = 0; j < label.LocalStyle.Group.Children.Count; j++)
                {
                    if (label.LocalStyle.Group.Children[j] is Text)
                    {
                        var text = (Text) label.LocalStyle.Group.Children[j];
                        double value = 0.0;
                        if (solution.Solution.Length > i)
                            value = solution.Solution[i];
                        text.TheText = String.Format("{0} = {1}", solution.Names[i], value);
                    }
                }
            }

            SetImage();
        }
Exemple #2
0
        private LPsolveSolution SolveIt(int lp)
        {
            LPsolve.write_lp(lp, OutputFileName + ".lp");
              LPsolve.delete_lp(lp);
              lp = LPsolve.read_LP(OutputFileName + ".lp", 0, "");

              LastResult = LPsolve.solve(lp);
              ObjectiveValue = LastResult == lpsolve_return.INFEASIBLE ? double.NaN :
              LPsolve.get_objective(lp);

              if (LastResult == lpsolve_return.INFEASIBLE)
              {
            LPsolve.delete_lp(lp);
            lp = LPsolve.read_LP(OutputFileName + ".lp", 0, "");
            LPsolve.set_preferdual(lp, PreferDual);
            //LPsolve.set_simplextype(lp, lpsolve_simplextypes.SIMPLEX_DUAL_DUAL);
            LPsolve.set_basiscrash(lp, lpsolve_basiscrash.CRASH_MOSTFEASIBLE);
            LPsolve.set_presolve(lp, lpsolve_presolve.PRESOLVE_ROWS | lpsolve_presolve.PRESOLVE_COLS, LPsolve.get_presolveloops(lp));
            LastResult = LPsolve.solve(lp);
            ObjectiveValue = LastResult == lpsolve_return.INFEASIBLE ? double.NaN :
            LPsolve.get_objective(lp);
              }

              if (LastResult == lpsolve_return.INFEASIBLE)
              {
            LPsolve.delete_lp(lp);
            lp = LPsolve.read_LP(OutputFileName + ".lp", 0, "");
            LPsolve.set_simplextype(lp, lpsolve_simplextypes.SIMPLEX_DUAL_PRIMAL);
            LPsolve.set_scaling(lp, lpsolve_scales.SCALE_EQUILIBRATE | lpsolve_scales.SCALE_INTEGERS);
            LPsolve.set_pivoting(lp, lpsolve_piv_rules.PRICER_STEEPESTEDGE | lpsolve_piv_rules.PRICE_ADAPTIVE);
            LPsolve.set_anti_degen(lp, lpsolve_anti_degen.ANTIDEGEN_FIXEDVARS | lpsolve_anti_degen.ANTIDEGEN_STALLING);
            LPsolve.set_basiscrash(lp, lpsolve_basiscrash.CRASH_NOTHING);
            LPsolve.set_presolve(lp, lpsolve_presolve.PRESOLVE_NONE, LPsolve.get_presolveloops(lp));
            LPsolve.set_improve(lp, lpsolve_improves.IMPROVE_DUALFEAS | lpsolve_improves.IMPROVE_THETAGAP);
            LastResult = LPsolve.solve(lp);
            ObjectiveValue = LastResult == lpsolve_return.INFEASIBLE ? double.NaN :
            LPsolve.get_objective(lp);
              }

              if (OutputFileName != "" && PrintDebug)
              {
            LPsolve.print_str(lp,
                          string.Concat(new object[] { LastResult, ": ", LPsolve.get_objective(lp), "\n" }));
            LPsolve.print_lp(lp);
            LPsolve.print_objective(lp);
            LPsolve.print_solution(lp, 1);
            LPsolve.print_constraints(lp, 1);
            LPsolve.set_outputfile(lp, null);
              }

              int numColumns = LPsolve.get_Ncolumns(lp);
              var numArray2 = new double[numColumns];

              LPsolve.get_variables(lp, ref numArray2[0]);
              var solution = new double[numColumns];
              var solutionNames = new List<string>();

              for (var i = 0; i < numColumns; i++)
              {
            solution[i] = numArray2[i];
            string name = LPsolve.get_col_name(lp, i + 1);
            solutionNames.Add(name);
              }

              LPsolve.delete_lp(lp);

              // generate results
              LastSolution = new LPsolveSolution(solution, solutionNames);
              return LastSolution;
        }