Search in sources :

Example 1 with OpfConstraintType

use of com.interpss.opf.datatype.OpfConstraintType in project ipss-plugin by InterPSS-Project.

the class ApacheLpsolveSolverInputBuilder method buildInput.

public void buildInput() {
    for (OpfConstraint conIn : cstContainer) {
        IntArrayList idx = conIn.getColNo();
        DoubleArrayList val = conIn.getVal();
        // output constraint to constraint collection
        OpenMapRealVector vec = new OpenMapRealVector(numOfVar);
        LinearConstraint con = null;
        OpfConstraintType type = conIn.getCstType();
        try {
            if (type.equals(OpfConstraintType.EQUALITY)) {
                double rh = conIn.getLowerLimit();
                for (int j = 0; j < idx.size(); j++) {
                    int colIdx = idx.elements()[j];
                    double posVal = val.elements()[j];
                    vec.setEntry(colIdx, posVal);
                }
                con = new LinearConstraint(vec, Relationship.EQ, rh);
            } else if (type.equals(OpfConstraintType.LARGER_THAN)) {
                double[] valRow = val.elements();
                double rh = conIn.getLowerLimit();
                double[] valRow_r = valRow;
                for (int ii = 0; ii < idx.size(); ii++) {
                    valRow_r[ii] = valRow[ii] * (-1);
                    int colIdx = idx.elements()[ii];
                    double posVal = valRow_r[ii];
                    vec.setEntry(colIdx, posVal);
                }
                con = new LinearConstraint(vec, Relationship.LEQ, -rh);
            } else if (type.equals(OpfConstraintType.LESS_THAN)) {
                double[] valRow = val.elements();
                double rh = conIn.getUpperLimit();
                for (int j = 0; j < idx.size(); j++) {
                    int colIdx = idx.elements()[j];
                    double posVal = valRow[j];
                    vec.setEntry(colIdx, posVal);
                }
                con = new LinearConstraint(vec, Relationship.LEQ, rh);
            }
            constCol.add(con);
        } catch (Exception e) {
            OPFLogger.getLogger().severe(e.toString() + " at constraint: " + conIn.getDesc());
        // e.printStackTrace();
        }
    }
}
Also used : LinearConstraint(org.apache.commons.math3.optimization.linear.LinearConstraint) OpfConstraintType(com.interpss.opf.datatype.OpfConstraintType) OpenMapRealVector(org.apache.commons.math3.linear.OpenMapRealVector) IntArrayList(cern.colt.list.IntArrayList) DoubleArrayList(cern.colt.list.DoubleArrayList) OpfConstraint(org.interpss.plugin.opf.constraint.OpfConstraint) OpfConstraint(org.interpss.plugin.opf.constraint.OpfConstraint) LinearConstraint(org.apache.commons.math3.optimization.linear.LinearConstraint)

Example 2 with OpfConstraintType

use of com.interpss.opf.datatype.OpfConstraintType in project ipss-plugin by InterPSS-Project.

the class LpsolveSolverInputBuilder method buildInput.

public void buildInput(LpSolve lpsolver) {
    for (OpfConstraint con : cstContainer) {
        IntArrayList idx = con.getColNo();
        DoubleArrayList val = con.getVal();
        int[] inIdx = new int[idx.size()];
        for (int j = 0; j < idx.size(); j++) {
            inIdx[j] = idx.elements()[j] + 1;
        }
        try {
            OpfConstraintType type = con.getCstType();
            if (type.equals(OpfConstraintType.EQUALITY)) {
                double rh = con.getLowerLimit();
                lpsolver.addConstraintex(idx.size(), val.elements(), inIdx, LpSolve.EQ, rh);
            } else if (type.equals(OpfConstraintType.LARGER_THAN)) {
                double[] valRow = val.elements();
                double rh = con.getLowerLimit();
                if (idx.size() == 1 && valRow[0] == 1) {
                    lpsolver.setLowbo(inIdx[0], rh);
                } else {
                    double[] valRow_r = valRow;
                    for (int ii = 0; ii < valRow.length; ii++) {
                        valRow_r[ii] = valRow[ii] * (-1);
                    }
                    lpsolver.addConstraintex(idx.size(), valRow_r, inIdx, LpSolve.LE, -rh);
                // lpsolver.addConstraintex( idx.size(), valRow, inIdx, LpSolve.GE, rh);
                }
            } else if (type.equals(OpfConstraintType.LESS_THAN)) {
                double[] valRow = val.elements();
                double rh = con.getUpperLimit();
                if (idx.size() == 1 && valRow[0] == 1) {
                    lpsolver.setUpbo(inIdx[0], rh);
                } else {
                    lpsolver.addConstraintex(idx.size(), val.elements(), inIdx, LpSolve.LE, rh);
                }
            }
        } catch (LpSolveException e) {
            OPFLogger.getLogger().severe(e.toString());
        }
    }
}
Also used : LpSolveException(lpsolve.LpSolveException) OpfConstraintType(com.interpss.opf.datatype.OpfConstraintType) IntArrayList(cern.colt.list.IntArrayList) DoubleArrayList(cern.colt.list.DoubleArrayList) OpfConstraint(org.interpss.plugin.opf.constraint.OpfConstraint) OpfConstraint(org.interpss.plugin.opf.constraint.OpfConstraint)

Example 3 with OpfConstraintType

use of com.interpss.opf.datatype.OpfConstraintType in project ipss-plugin by InterPSS-Project.

the class GIQPSolverInputMatrixBuilder method buildCiqAndBiq.

public void buildCiqAndBiq(SparseDoubleMatrix2D Ciq, SparseDoubleMatrix1D biq, int startIdx, int endIdx) {
    int cnt = 0;
    for (OpfConstraint con : cstContainer) {
        IntArrayList idx = con.getColNo();
        DoubleArrayList val = con.getVal();
        OpfConstraintType type = con.getCstType();
        if (type.equals(OpfConstraintType.LARGER_THAN)) {
            for (int j = 0; j < idx.size(); j++) {
                Ciq.set(cnt, idx.get(j), val.get(j));
            }
            double rh = con.getLowerLimit();
            biq.set(cnt, rh);
            cnt++;
        } else if (type.equals(OpfConstraintType.LESS_THAN)) {
            for (int j = 0; j < idx.size(); j++) {
                Ciq.set(cnt, idx.get(j), -val.get(j));
            }
            double rh = con.getUpperLimit();
            biq.set(cnt, -rh);
            cnt++;
        }
    }
}
Also used : OpfConstraintType(com.interpss.opf.datatype.OpfConstraintType) IntArrayList(cern.colt.list.IntArrayList) DoubleArrayList(cern.colt.list.DoubleArrayList) OpfConstraint(org.interpss.plugin.opf.constraint.OpfConstraint) OpfConstraint(org.interpss.plugin.opf.constraint.OpfConstraint)

Aggregations

DoubleArrayList (cern.colt.list.DoubleArrayList)3 IntArrayList (cern.colt.list.IntArrayList)3 OpfConstraintType (com.interpss.opf.datatype.OpfConstraintType)3 OpfConstraint (org.interpss.plugin.opf.constraint.OpfConstraint)3 LpSolveException (lpsolve.LpSolveException)1 OpenMapRealVector (org.apache.commons.math3.linear.OpenMapRealVector)1 LinearConstraint (org.apache.commons.math3.optimization.linear.LinearConstraint)1