Class LPMatrix.DENSE.GUROBI

  • All Implemented Interfaces:
    LPMatrix<gurobi.GRBModel>
    Enclosing class:
    LPMatrix.DENSE

    public static class LPMatrix.DENSE.GUROBI
    extends java.lang.Object
    The dense variant for the Gurobi external solver. Needs a GurobiEnvironment as input.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String[] colNames  
      protected byte[] integer  
      protected boolean isMinimizing  
      protected double[] lowBo  
      protected double[][] matrix  
      protected double[] obj  
      protected int offset  
      protected double[] rhs  
      protected java.lang.String[] rowNames  
      protected int solverResult  
      protected byte[] types  
      protected double[] upBo  
    • Constructor Summary

      Constructors 
      Constructor Description
      GUROBI​(gurobi.GRBEnv env, int rows, int columns)  
      GUROBI​(gurobi.GRBEnv env, LPMatrix<?> matrix)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void adjustMat​(int row, int column, double value)
      adjusts the value at index row, column in the matrix.
      int bytesUsed()
      returns the number of bytes occupied by the main arrays in this class.
      java.lang.String getColName​(int column)
      Gets the name of a column, or null if there is none.
      java.lang.String[] getColNames()
      Returns the column names or null if there are none.
      byte getConstrType​(int r)  
      int getLastSolverResult()
      returns the last result returned by the external solver.
      double getlowBo​(int c)  
      double getMat​(int row, int column)
      Return the value at index row, column in the MIP matrix.
      int getNcolumns()  
      int getNrows()  
      double getObjective​(int column)  
      int getOffset()  
      double getRh​(int row)  
      protected double[] getRow​(int row)  
      java.lang.String getRowName​(int r)  
      java.lang.String[] getRowNames()  
      double getUpBo​(int c)  
      byte getVarType​(int c)  
      double objectiveValue​(double[] vars)  
      void printLp​(java.io.OutputStreamWriter writer, java.lang.String sep)
      prints the LP to the given outputWriter using the given separator character as separator.
      void printLpToCSV​(java.lang.String fileName)
      Prints the MIP to a CSV file using ";" as a separator character.
      double product​(double[] vars, int fromIncluding, int toExcluding, int row)  
      void setBinary​(int c, boolean b)  
      void setColName​(int column, java.lang.String name)
      Sets the name of a column.
      void setConstrType​(int row, byte type)  
      void setInt​(int column, boolean isInt)  
      void setLowbo​(int column, double value)  
      void setMat​(int row, int column, double value)
      set the value at index row, column in the matrix.
      void setMaxim()  
      void setMinim()  
      void setObjective​(int column, double value)  
      void setRh​(int row, double value)  
      void setRhVec​(double[] rhs)  
      void setRowName​(int row, java.lang.String name)
      Sets the name of a row.
      void setUpbo​(int column, double value)  
      int solve​(double[] vars)
      Constructs the solver and solves the MIP represented by this problem.
      gurobi.GRBModel toSolver()
      Constructs the solver in its external representation
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • matrix

        protected final double[][] matrix
      • offset

        protected final int offset
      • rhs

        protected final double[] rhs
      • types

        protected final byte[] types
      • rowNames

        protected java.lang.String[] rowNames
      • obj

        protected final double[] obj
      • upBo

        protected final double[] upBo
      • lowBo

        protected final double[] lowBo
      • colNames

        protected java.lang.String[] colNames
      • integer

        protected final byte[] integer
      • isMinimizing

        protected boolean isMinimizing
      • solverResult

        protected int solverResult
    • Constructor Detail

      • GUROBI

        public GUROBI​(gurobi.GRBEnv env,
                      int rows,
                      int columns)
      • GUROBI

        public GUROBI​(gurobi.GRBEnv env,
                      LPMatrix<?> matrix)
    • Method Detail

      • solve

        public int solve​(double[] vars)
                  throws LPMatrixException
        Description copied from interface: LPMatrix
        Constructs the solver and solves the MIP represented by this problem. The returned value is either OPTIMAL, INFEASIBLE or OTHER. The external solver's result can be obtained through getLastSolverResult()
        Parameters:
        vars - an array dimensioned in the number of columns, i.e. vars.length == getNColumns(). This is not checked!
        Returns:
        Throws:
        LPMatrixException - if the external solver throws an exception
      • getMat

        public double getMat​(int row,
                             int column)
        Description copied from interface: LPMatrix
        Return the value at index row, column in the MIP matrix.
        Returns:
      • setMat

        public void setMat​(int row,
                           int column,
                           double value)
        Description copied from interface: LPMatrix
        set the value at index row, column in the matrix.
      • adjustMat

        public void adjustMat​(int row,
                              int column,
                              double value)
        Description copied from interface: LPMatrix
        adjusts the value at index row, column in the matrix.
      • getNrows

        public int getNrows()
      • getNcolumns

        public int getNcolumns()
      • getRow

        protected double[] getRow​(int row)
      • bytesUsed

        public int bytesUsed()
        returns the number of bytes occupied by the main arrays in this class.
        Returns:
      • getLastSolverResult

        public int getLastSolverResult()
        Description copied from interface: LPMatrix
        returns the last result returned by the external solver. This method only makes sense after a call to solve() that did not throw an exception.
        Specified by:
        getLastSolverResult in interface LPMatrix<S>
        Returns:
      • setInt

        public void setInt​(int column,
                           boolean isInt)
        Specified by:
        setInt in interface LPMatrix<S>
      • setUpbo

        public void setUpbo​(int column,
                            double value)
        Specified by:
        setUpbo in interface LPMatrix<S>
      • setLowbo

        public void setLowbo​(int column,
                             double value)
        Specified by:
        setLowbo in interface LPMatrix<S>
      • setColName

        public void setColName​(int column,
                               java.lang.String name)
        Description copied from interface: LPMatrix
        Sets the name of a column. Setting names is not required and no memory is reserved for column names until the first name is set on a column.
        Specified by:
        setColName in interface LPMatrix<S>
      • setRowName

        public void setRowName​(int row,
                               java.lang.String name)
        Description copied from interface: LPMatrix
        Sets the name of a row. Setting names is not required and no memory is reserved for row names until the first name is set on a row.
        Specified by:
        setRowName in interface LPMatrix<S>
      • setConstrType

        public void setConstrType​(int row,
                                  byte type)
        Specified by:
        setConstrType in interface LPMatrix<S>
      • setMaxim

        public void setMaxim()
        Specified by:
        setMaxim in interface LPMatrix<S>
      • setMinim

        public void setMinim()
        Specified by:
        setMinim in interface LPMatrix<S>
      • setRhVec

        public void setRhVec​(double[] rhs)
        Specified by:
        setRhVec in interface LPMatrix<S>
      • setRh

        public void setRh​(int row,
                          double value)
        Specified by:
        setRh in interface LPMatrix<S>
      • setObjective

        public void setObjective​(int column,
                                 double value)
        Specified by:
        setObjective in interface LPMatrix<S>
      • getRh

        public double getRh​(int row)
        Specified by:
        getRh in interface LPMatrix<S>
      • getColName

        public java.lang.String getColName​(int column)
        Description copied from interface: LPMatrix
        Gets the name of a column, or null if there is none.
        Specified by:
        getColName in interface LPMatrix<S>
        Returns:
      • getObjective

        public double getObjective​(int column)
        Specified by:
        getObjective in interface LPMatrix<S>
      • getColNames

        public java.lang.String[] getColNames()
        Description copied from interface: LPMatrix
        Returns the column names or null if there are none.
        Specified by:
        getColNames in interface LPMatrix<S>
        Returns:
      • product

        public double product​(double[] vars,
                              int fromIncluding,
                              int toExcluding,
                              int row)
        Specified by:
        product in interface LPMatrix<S>
      • objectiveValue

        public double objectiveValue​(double[] vars)
        Specified by:
        objectiveValue in interface LPMatrix<S>
      • setBinary

        public void setBinary​(int c,
                              boolean b)
        Specified by:
        setBinary in interface LPMatrix<S>
      • printLp

        public void printLp​(java.io.OutputStreamWriter writer,
                            java.lang.String sep)
                     throws java.io.IOException
        Description copied from interface: LPMatrix
        prints the LP to the given outputWriter using the given separator character as separator. The output of this method on System.out, with "\t" as the separator returns the same representation as LpSolve's printLp() method.
        Specified by:
        printLp in interface LPMatrix<S>
        Throws:
        java.io.IOException
      • getOffset

        public int getOffset()
        Specified by:
        getOffset in interface LPMatrix<S>
      • printLpToCSV

        public void printLpToCSV​(java.lang.String fileName)
                          throws java.io.IOException
        Description copied from interface: LPMatrix
        Prints the MIP to a CSV file using ";" as a separator character. If row and column names are provided they are printed, otherwise, they are numbered
        Specified by:
        printLpToCSV in interface LPMatrix<S>
        Throws:
        java.io.IOException
      • getRowNames

        public java.lang.String[] getRowNames()
        Specified by:
        getRowNames in interface LPMatrix<S>
      • getVarType

        public byte getVarType​(int c)
        Specified by:
        getVarType in interface LPMatrix<S>
      • getlowBo

        public double getlowBo​(int c)
        Specified by:
        getlowBo in interface LPMatrix<S>
      • getUpBo

        public double getUpBo​(int c)
        Specified by:
        getUpBo in interface LPMatrix<S>
      • getConstrType

        public byte getConstrType​(int r)
        Specified by:
        getConstrType in interface LPMatrix<S>
      • getRowName

        public java.lang.String getRowName​(int r)
        Specified by:
        getRowName in interface LPMatrix<S>