Ejemplo n.º 1
0
        //public class LinearSolutionEventArgs : EventArgs
        //{
        //    public int VariableCount { get; private set; }

        //    public int ConstraintCount { get; private set; }

        //    public LinearResultStatus ResultStatus { get; private set; }

        //    public dynamic SolutionValues { get; private set; }

        //    internal LinearSolutionEventArgs(int variableCount, int constraintCount, LinearResultStatus resultStatus,
        //        dynamic solutionValues)
        //    {
        //        VariableCount = variableCount;
        //        ConstraintCount = constraintCount;
        //        ResultStatus = resultStatus;
        //        SolutionValues = solutionValues;
        //    }
        //}

        //public event EventHandler<LinearSolutionEventArgs> Solved;

        //private void OnSolved(LinearSolutionEventArgs e)
        //{
        //    Solved?.Invoke(this, e);
        //}

        protected override void ReceiveSolution(Solver solver, LinearResultStatus resultStatus, dynamic problem)
        {
            var solution = resultStatus == Optimal || resultStatus == Feasible;
            var e        = new SolutionEventArgs(solver, resultStatus, solution, GetSolutionValues(problem));

            OnSolved(e);
        }
Ejemplo n.º 2
0
        public void VerifyThatFeasibilityProblemSolverCorrect()
        {
            Func <double, double> round = Math.Round;

            using (var s = new FeasibleRegionProblemSolver())
            {
                s.Solved += (sender, e) =>
                {
                    const LinearResultStatus optimal = Optimal;

                    /* The numbers really ARE NOT that perfect, they are CLOSE, within fraction
                     * of 0.0001, but for rounding. It is also not necessarily the case where
                     * Rounding is a Solver issue, but a unit test one. */

                    Assert.That(e.VariableCount, Is.EqualTo(2));
                    Assert.That(e.ConstraintCount, Is.EqualTo(3));
                    Assert.That(e.ResultStatus, Is.EqualTo(optimal));
                    Assert.That(round(e.Solution), Is.EqualTo(34d));
                    Assert.That(round(e.SolutionValues.x), Is.EqualTo(6d));
                    Assert.That(round(e.SolutionValues.y), Is.EqualTo(4d));
                };

                Assert.That(s.TryResolve(), Is.True);
            }
        }
 /// <summary>
 /// Internal Constructor
 /// </summary>
 /// <param name="solver"></param>
 /// <param name="resultStatus"></param>
 /// <param name="solution"></param>
 /// <param name="solutionValues"></param>
 /// <inheritdoc />
 public SolutionEventArgs(Solver solver, LinearResultStatus resultStatus, TSolution solution
                          , dynamic solutionValues)
 {
     VariableCount   = solver.NumVariables();
     ConstraintCount = solver.NumConstraints();
     ResultStatus    = resultStatus;
     Solution        = solution;
     SolutionValues  = solutionValues;
 }
Ejemplo n.º 4
0
 // ReSharper disable once UnusedMember.Global
 /// <summary>
 /// Receives the <paramref name="resultStatus"/> and <paramref name="problem"/>.
 /// </summary>
 /// <param name="solver"></param>
 /// <param name="resultStatus"></param>
 /// <param name="problem"></param>
 protected abstract void ReceiveSolution(Solver solver, LinearResultStatus resultStatus, dynamic problem);
 /// <summary>
 /// Receives the <paramref name="solution"/> and <paramref name="resultStatus"/>.
 /// </summary>
 /// <param name="solver"></param>
 /// <param name="resultStatus"></param>
 /// <param name="solution"></param>
 /// <param name="problem"></param>
 protected void ReceiveSolution(Solver solver, LinearResultStatus resultStatus,
                                TSolution solution, dynamic problem)
 {
     OnSolved(new SolutionEventArgs(solver, resultStatus, solution, GetSolutionValues(problem)));
 }
 /// <summary>
 /// Verifies the <paramref name="solver"/> Solution.
 /// </summary>
 /// <param name="solver"></param>
 /// <param name="resultStatus"></param>
 /// <returns></returns>
 protected virtual bool VerifySolution(Solver solver, LinearResultStatus resultStatus)
 {
     return(AcceptableResultStatuses.Contains(resultStatus));
 }
Ejemplo n.º 7
0
 protected override bool VerifySolution(Solver solver, LinearResultStatus resultStatus)
 {
     /* The solution looks legit; however, when using solvers other than GLOP_LINEAR_PROGRAMMING,
      * verifying the solution is highly recommended! */
     return(base.VerifySolution(solver, resultStatus) && solver.VerifySolution(1e-7, true));
 }