fuzzydl.milp

## Class MILPHelper

- java.lang.Object
- - fuzzydl.milp.MILPHelper

-     public class MILPHelper
      extends java.lang.Object

  MILP problem manager, storing the problem and calling an external solver.
  Author:
    Fernando Bobillo

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static boolean` | `PRINT_LABELS` Indicates whether we want to show the membership degrees to linguistic labels or not.
    `static boolean` | `PRINT_VARIABLES` Indicates whether we want to show the value of the variables or not.
    `ShowVariablesHelper` | `showVars` Manages displayed variables.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MILPHelper()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addContradiction()` Add a contradiction to make the fuzzy KB unsatisfiable
    `void` | `addCrispConcept(java.lang.String conceptName)` Defines a concept to be crisp.
    `void` | `addCrispRole(java.lang.String roleName)` Defines a role to be crisp.
    `void` | `addEquality(Variable var1, Variable var2)` Add an equality of the form: var1 = var2.
    `void` | `addNewConstraint(Assertion ass)` Adds a new inequality encoded in a fuzzy assertion.
    `void` | `addNewConstraint(Assertion ass, double n)` Given a fuzzy assertion a:C >= L and a number n, adds an inequality of the form: xAss >= n.
    `void` | `addNewConstraint(Expression expr, char constraintType)` Adds a new inequality of the form: expr constraintType 0.
    `void` | `addNewConstraint(Expression expr, char constraintType, Degree degree)` Adds a new inequality of the form: expr constraintType degree.
    `void` | `addNewConstraint(Expression expr, char constraintType, double n)` Adds a new inequality of the form: expr constraintType n.
    `void` | `addNewConstraint(Variable x, Degree D)` Add an inequality of the form: x >= D.
    `void` | `addNewConstraint(Variable x, double n)` Adds a new inequality of the form: x >= n.
    `void` | `addStringFeature(java.lang.String role)` Adds a string feature.
    `void` | `addStringValue(java.lang.String value, int intValue)` Relates the value of a string feature with an integer value.
    `void` | `changeVariableNames(java.lang.String oldName, java.lang.String newName, boolean oldIsCreatedIndividual)` Replaces the name of the variables including an individual name with the name of another individual name.
    `MILPHelper` | `clone()` Gets a copy of the object.
    `boolean` | `existsNominalVariable(java.lang.String i)` Exists a variable taking the value of an individual i belonging to the nominal concept {i.
    `Variable` | `getNegatedNominalVariable(java.lang.String i1, java.lang.String i2)` Gets a variable taking the value of an individual i1 not belonging to the nominal concept {i2}.
    `Variable` | `getNewVariable(char type)` Gets a new variable with the indicated type.
    `Variable` | `getNominalVariable(java.lang.String i1)` Gets a variable taking the value of an individual i belonging to the nominal concept {i}.
    `Variable` | `getNominalVariable(java.lang.String i1, java.lang.String i2)` Gets a variable taking the value of an individual i1 belonging to the nominal concept {i2}.
    `int` | `getNumberForAssertion(Assertion ass)` Gets an integer codification of an assertion.
    `Variable[]` | `getOrderedPermutation(Variable[] x)`
    `Variable[]` | `getOrderedPermutation(Variable[] x, Variable[][] z)` Gets an ordered permutation of the variables.
    `Variable` | `getVariable(Assertion ass)` Gets a variable taking the value of a concept assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
    `Variable` | `getVariable(CreatedIndividual ind)` Gets a variable taking the value of a concrete individual.
    `Variable` | `getVariable(CreatedIndividual ind, char bound)` Gets a variable taking the value of a concrete individual.
    `Variable` | `getVariable(Individual ind, Concept c)` Gets a variable taking the value of a concept assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
    `Variable` | `getVariable(Individual a, Individual b, java.lang.String role)` Gets a variable taking the value of a role assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
    `Variable` | `getVariable(Individual a, Individual b, java.lang.String role, char type)` Gets a variable taking the value of a role assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
    `Variable` | `getVariable(Individual ind, Restriction restric)` Gets a variable taking the value of a universal restriction, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
    `Variable` | `getVariable(Individual ind, java.lang.String conceptName)` Gets a variable taking the value of a concept assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
    `Variable` | `getVariable(Relation rel)` Gets a variable taking the value of a role assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
    `Variable` | `getVariable(java.lang.String name)` Gets a variable with the given name, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
    `Variable` | `getVariable(java.lang.String varName, char type)` Gets a variable with the indicated name and bound.
    `boolean` | `hasVariable(Assertion ass)` Cheks if there is a variable for a concept assertion.
    `boolean` | `hasVariable(java.lang.String name)` Cheks if there is a variable with the given name.
    `boolean` | `isCrispConcept(java.lang.String conceptName)` Checks if a concept is crisp or not.
    `boolean` | `isCrispRole(java.lang.String roleName)` Checks if a role is crisp or not.
    `Solution` | `optimize(Expression objective)` It optimizes an expression.
    `void` | `printInstanceOfLabels(java.lang.String fName, java.lang.String indName, double value)` Shows the membership degrees to some linguistic labels.
    `void` | `setBinaryVariables()` Transforms every [0,1]-variable into a {0,1} variable.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### PRINT_LABELS

          public static boolean PRINT_LABELS

      Indicates whether we want to show the membership degrees to linguistic labels or not.

    - #### PRINT_VARIABLES

          public static boolean PRINT_VARIABLES

      Indicates whether we want to show the value of the variables or not.

    - #### showVars

          public ShowVariablesHelper showVars

      Manages displayed variables.

  - ### Constructor Detail

    - #### MILPHelper

          public MILPHelper()

  - ### Method Detail

    - #### clone

          public MILPHelper clone()

      Gets a copy of the object.
      Overrides:
        `clone` in class `java.lang.Object`
      Returns:
        A copy of the object.

    - #### optimize

          public Solution optimize(Expression objective)

      It optimizes an expression.
      Parameters:
        `objective` - Expression to be optimized.
      Returns:
        An optimal solution of the expression.

    - #### printInstanceOfLabels

          public void printInstanceOfLabels(java.lang.String fName,
                                            java.lang.String indName,
                                            double value)

      Shows the membership degrees to some linguistic labels.
      Parameters:
        `fName` - Name of the feature.
        `indName` - Name of the individual.
        `value` - Value of the feature for the given individual.

    - #### getNewVariable

          public Variable getNewVariable(char type)

      Gets a new variable with the indicated type.
      Parameters:
        `type` - Type of the new variable.
      Returns:
        A new variable with the indicated bound.

    - #### getVariable

          public Variable getVariable(java.lang.String varName,
                                      char type)

      Gets a variable with the indicated name and bound.
      Parameters:
        `varName` - Name of the variable.
        `type` - Type of the variable.
      Returns:
        A new variable with the indicated type.

    - #### getVariable

          public Variable getVariable(java.lang.String name)

      Gets a variable with the given name, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
      Parameters:
        `name` - Name of the variable.
      Returns:
        A variable with the given name.

    - #### hasVariable

          public boolean hasVariable(java.lang.String name)

      Cheks if there is a variable with the given name.
      Parameters:
        `name` - Name of the variable.
      Returns:
        true if the variable exists; false otherwise

    - #### hasVariable

          public boolean hasVariable(Assertion ass)

      Cheks if there is a variable for a concept assertion.
      Parameters:
        `ass` - An assertion.
      Returns:
        true if the variable exists; false otherwise

    - #### getNominalVariable

          public Variable getNominalVariable(java.lang.String i1)

      Gets a variable taking the value of an individual i belonging to the nominal concept {i}.
      Parameters:
        `i1` - An individual.
      Returns:
        A variable taking the value of the assertion i : {i}.

    - #### existsNominalVariable

          public boolean existsNominalVariable(java.lang.String i)

      Exists a variable taking the value of an individual i belonging to the nominal concept {i.
      Parameters:
        `i` - An individual.
      Returns:
        true if there is a variable taking the value of the assertion i: {i}; false otherwise

    - #### getNominalVariable

          public Variable getNominalVariable(java.lang.String i1,
                                             java.lang.String i2)

      Gets a variable taking the value of an individual i1 belonging to the nominal concept {i2}.
      Parameters:
        `i1` - An individual that is subject of the assertion.
        `i2` - An individual representing the nominal concept.
      Returns:
        A variable taking the value of the assertion i1: {i2}.

    - #### getNegatedNominalVariable

          public Variable getNegatedNominalVariable(java.lang.String i1,
                                                    java.lang.String i2)

      Gets a variable taking the value of an individual i1 not belonging to the nominal concept {i2}.
      Parameters:
        `i1` - An individual that is subject of the assertion.
        `i2` - An individual representing the nominal concept.
      Returns:
        A variable taking the value of the assertion i1: not {i2}.

    - #### getVariable

          public Variable getVariable(Assertion ass)

      Gets a variable taking the value of a concept assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
      Parameters:
        `ass` - A fuzzy concept assertion.
      Returns:
        A variable taking the value of the assertion.

    - #### getVariable

          public Variable getVariable(Relation rel)

      Gets a variable taking the value of a role assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
      Parameters:
        `rel` - A fuzzy role assertion.
      Returns:
        A variable taking the value of the assertion.

    - #### getVariable

          public Variable getVariable(Individual ind,
                                      Restriction restric)

      Gets a variable taking the value of a universal restriction, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
      Parameters:
        `ind` - Subject individual of the restrictions.
        `restric` - A fuzzy universal restriction.
      Returns:
        A variable taking the value of the assertion.

    - #### getVariable

          public Variable getVariable(Individual ind,
                                      Concept c)

      Gets a variable taking the value of a concept assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
      Parameters:
        `ind` - An individual.
        `c` - A fuzzy concept.
      Returns:
        A variable taking the value of the assertion.

    - #### getVariable

          public Variable getVariable(Individual ind,
                                      java.lang.String conceptName)

      Gets a variable taking the value of a concept assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
      Parameters:
        `ind` - An individual.
        `conceptName` - A fuzzy concept name.
      Returns:
        A variable taking the value of the assertion.

    - #### getVariable

          public Variable getVariable(Individual a,
                                      Individual b,
                                      java.lang.String role)

      Gets a variable taking the value of a role assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
      Parameters:
        `a` - Object individual.
        `b` - Subject individual.
        `role` - Role.
      Returns:
        A variable taking the value of the assertion.

    - #### getVariable

          public Variable getVariable(Individual a,
                                      Individual b,
                                      java.lang.String role,
                                      char type)

      Gets a variable taking the value of a role assertion, creating a new one of type UP_BOUND_BY_ONE if it does not exist.
      Parameters:
        `a` - Object individual.
        `b` - Subject individual.
        `role` - Role.
        `type` - Type of the variable.
      Returns:
        A variable taking the value of the assertion.

    - #### getVariable

          public Variable getVariable(CreatedIndividual ind)

      Gets a variable taking the value of a concrete individual.
      Parameters:
        `ind` - A concrete individual.
      Returns:
        A variable taking the value of the individual.

    - #### getVariable

          public Variable getVariable(CreatedIndividual ind,
                                      char bound)

      Gets a variable taking the value of a concrete individual.
      Parameters:
        `ind` - A concrete individual.
        `bound` - char to the variable.
      Returns:
        A variable taking the value of the individual.

    - #### addNewConstraint

          public void addNewConstraint(Expression expr,
                                       char constraintType)

      Adds a new inequality of the form: expr constraintType 0.
      Parameters:
        `expr` - An expression in the left side of the inequality.
        `constraintType` - Type of the constraint (EQ, GR, LE).

    - #### addNewConstraint

          public void addNewConstraint(Variable x,
                                       double n)

      Adds a new inequality of the form: x >= n.
      Parameters:
        `x` - A variable.
        `n` - A real number.

    - #### addNewConstraint

          public void addNewConstraint(Assertion ass,
                                       double n)

      Given a fuzzy assertion a:C >= L and a number n, adds an inequality of the form: xAss >= n.
      Parameters:
        `ass` - A fuzzy assertion.
        `n` - A real number.

    - #### addNewConstraint

          public void addNewConstraint(Variable x,
                                       Degree D)

      Add an inequality of the form: x >= D.
      Parameters:
        `x` - A fuzzy assertion.
        `D` - A degree.

    - #### addNewConstraint

          public void addNewConstraint(Assertion ass)

      Adds a new inequality encoded in a fuzzy assertion.
      Parameters:
        `ass` - A fuzzy assertion.

    - #### addNewConstraint

          public void addNewConstraint(Expression expr,
                                       char constraintType,
                                       Degree degree)

      Adds a new inequality of the form: expr constraintType degree.
      Parameters:
        `expr` - An expression in the left side of the inequality.
        `constraintType` - Type of the constraint (EQ, GR, LE).
        `degree` - A degree in the right side of the inequality.

    - #### addNewConstraint

          public void addNewConstraint(Expression expr,
                                       char constraintType,
                                       double n)

      Adds a new inequality of the form: expr constraintType n.
      Parameters:
        `expr` - An expression in the left side of the inequality.
        `constraintType` - Type of the constraint (EQ, GR, LE).
        `n` - A real number expression in the right side of the inequality.

    - #### addEquality

          public void addEquality(Variable var1,
                                  Variable var2)

      Add an equality of the form: var1 = var2.
      Parameters:
        `var1` - A variable.
        `var2` - Another variable.

    - #### addStringFeature

          public void addStringFeature(java.lang.String role)

      Adds a string feature.
      Parameters:
        `role` - A string feature.

    - #### addStringValue

          public void addStringValue(java.lang.String value,
                                     int intValue)

      Relates the value of a string feature with an integer value.
      Parameters:
        `value` - Value of a string feature.
        `intValue` - Corresponding integer value.

    - #### changeVariableNames

          public void changeVariableNames(java.lang.String oldName,
                                          java.lang.String newName,
                                          boolean oldIsCreatedIndividual)

      Replaces the name of the variables including an individual name with the name of another individual name.
      Parameters:
        `oldName` - Old individual name.
        `newName` - New individual name.
        `oldIsCreatedIndividual` - Indicates whether the old individual is a created individual or not.

    - #### getOrderedPermutation

          public Variable[] getOrderedPermutation(Variable[] x)

    - #### getOrderedPermutation

          public Variable[] getOrderedPermutation(Variable[] x,
                                                  Variable[][] z)

      Gets an ordered permutation of the variables.
      Parameters:
        `x` - A vector of input variables.
        `z` - A matrix of intermediate variables.
      Returns:
        A permutation of the input variables such that y[0] >= y[1] >= ... >= y[n-1]

    - #### addCrispConcept

          public void addCrispConcept(java.lang.String conceptName)

      Defines a concept to be crisp.
      Parameters:
        `conceptName` - A concept name.

    - #### addCrispRole

          public void addCrispRole(java.lang.String roleName)

      Defines a role to be crisp.
      Parameters:
        `roleName` - A role name.

    - #### isCrispConcept

          public boolean isCrispConcept(java.lang.String conceptName)

      Checks if a concept is crisp or not.
      Parameters:
        `conceptName` - A concept name.
      Returns:
        true if the concept is crisp; false otherwise.

    - #### isCrispRole

          public boolean isCrispRole(java.lang.String roleName)

      Checks if a role is crisp or not.
      Parameters:
        `roleName` - A role name.
      Returns:
        true if the role is crisp; false otherwise.

    - #### setBinaryVariables

          public void setBinaryVariables()

      Transforms every [0,1]-variable into a {0,1} variable.

    - #### getNumberForAssertion

          public int getNumberForAssertion(Assertion ass)

      Gets an integer codification of an assertion.
      Parameters:
        `ass` - An assertion.
      Returns:
        An integer codification of ass.

    - #### addContradiction

          public void addContradiction()

      Add a contradiction to make the fuzzy KB unsatisfiable