Exemplo n.º 1
0
 /// <summary>
 /// Builds a tableau for a linear problem.
 /// </summary>
 /// <param name="f">Linear objective function.</param>
 /// <param name="constraints">Linear constraints.</param>
 /// <param name="goalType">Optimization goal</param>
 /// <param name="restrictToNonNegative">Whether to restrict the variables to non-negative values.</param>
 /// <param name="epsilon">Amount of error to accept when checking for optimality.</param>
 public SimplexTableau(LinearObjectiveFunction <T, TPolicy> f,
                       ICollection <LinearConstraint <T, TPolicy> > constraints,
                       GoalType goalType,
                       bool restrictToNonNegative,
                       T epsilon) : this(f, constraints, goalType, restrictToNonNegative, epsilon, SimplexSolver <T, TPolicy> .DEFAULT_ULPS)
 {
 }
Exemplo n.º 2
0
 /// <summary>
 /// Build a tableau for a linear problem.
 /// </summary>
 /// <param name="f">linear objective function</param>
 /// <param name="constraints">linear constraints</param>
 /// <param name="goalType">type of optimization goal</param>
 /// <param name="restrictToNonNegative">whether to restrict the variables to non-negative values</param>
 /// <param name="epsilon">amount of error to accept when checking for optimality</param>
 /// <param name="maxUlps">amount of error to accept in floating point comparisons</param>
 public SimplexTableau(LinearObjectiveFunction <T, TPolicy> f,
                       ICollection <LinearConstraint <T, TPolicy> > constraints,
                       GoalType goalType,
                       bool restrictToNonNegative,
                       T epsilon,
                       int maxUlps)
 {
     CheckDimensions(f, constraints);
     this.f                     = f;
     this.constraints           = NormalizeConstraints(constraints);
     this.restrictToNonNegative = restrictToNonNegative;
     this.epsilon               = epsilon;
     this.maxUlps               = maxUlps;
     this.numDecisionVariables  = f.Coefficients.Count + (restrictToNonNegative ? 0 : 1);
     this.numSlackVariables     = ConstraintTypeCounts(Relationship.LEQ) +
                                  ConstraintTypeCounts(Relationship.GEQ);
     this.numArtificialVariables = ConstraintTypeCounts(Relationship.EQ) +
                                   ConstraintTypeCounts(Relationship.GEQ);
     this.tableau = CreateTableau(goalType == GoalType.MAXIMIZE);
     // initialize the basic variables for phase 1:
     //   we know that only slack or artificial variables can be basic
     InitializeBasicVariables(SlackVariableOffset);
     InitializeColumnLabels();
     GoalType = goalType;
 }
Exemplo n.º 3
0
        private void CheckDimensions(LinearObjectiveFunction <T, TPolicy> objectiveFunction,
                                     ICollection <LinearConstraint <T, TPolicy> > c)
        {
            int dimension = objectiveFunction.Coefficients.Count;

            foreach (LinearConstraint <T, TPolicy> constraint in c)
            {
                int constraintDimension = constraint.Coefficients.Count;
                if (constraintDimension != dimension)
                {
                    throw new DimensionMismatchException(constraintDimension, dimension);
                }
            }
        }