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();
}
}
}
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());
}
}
}
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++;
}
}
}
Aggregations