Commit abd962cc authored by Christoph Richter's avatar Christoph Richter
Browse files

Fixed bugs

parent 59a74e46
Pipeline #68776 failed with stage
in 21 seconds
......@@ -124,11 +124,11 @@ public class Problem {
/**
* Default value if no lower bound is set
*/
public final static String LOWER_BOUND_INF = "-1E+19";
public final static String LOWER_BOUND_INF = "-1E19";
/**
* Default value if no upper bound is set
*/
public final static String UPPER_BOUND_INF = "1E+19";
public final static String UPPER_BOUND_INF = "1E19";
/**
* number of constraints in function g
*/
......
......@@ -80,9 +80,27 @@ public class ProblemAssignmentHandler {
if (expr instanceof MathMatrixNameExpressionSymbol) {
MathMatrixNameExpressionSymbol matNameExpr = (MathMatrixNameExpressionSymbol) expr;
String indexExpr = ExecuteMethodGeneratorMatrixExpressionHandler.generateExecuteCode(matNameExpr.getMathMatrixAccessOperatorSymbol(), new ArrayList<>());
indexExpr = indexExpr.replaceAll(",", "+");
if (MathConverter.curBackend.usesZeroBasedIndexing()) {
indexExpr += " - " + matNameExpr.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols().size();
if (indexExpr.contains(".col") && indexExpr.contains(".row"))
indexExpr = "all";
else if (indexExpr.startsWith(".col"))
indexExpr = "\"col\", " + indexExpr.substring(indexExpr.indexOf("(") + 1, indexExpr.indexOf(")"));
else if (indexExpr.startsWith(".row"))
indexExpr = "\"row\", " + indexExpr.substring(indexExpr.indexOf("(") + 1, indexExpr.indexOf(")"));
else {
Vector<Integer> dims = p.getOptimizationVariableDimensions();
if (indexExpr.contains(",")) {
indexExpr = indexExpr.replaceAll(",", "+ (");
StringBuilder indexSB = new StringBuilder();
indexSB.append(indexExpr);
indexSB.insert(indexSB.length() - 1 ," - 1 ) * " + dims.get(0) + " ");
indexExpr = indexSB.toString();
}
if (MathConverter.curBackend.usesZeroBasedIndexing()) {
if (indexExpr.contains("+"))
indexExpr = indexExpr.replaceAll("\\+", "- 1 +");
else if (indexExpr.contains(")"))
indexExpr = indexExpr.substring(0, indexExpr.lastIndexOf(")")) + "- 1)";
}
}
String funcSigniture = String.format("%s, %s, %s", currXL, indexExpr, currXU);
xMatrixElementConstraints.add(funcSigniture);
......
......@@ -166,10 +166,122 @@ class ${viewModel.callSolverName}
}
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const double &lower, int index, const double &upper) {
static void addConstraintOnX(Dvector &xl, Dvector &xu, const double &lower, const int index, const double &upper) {
xl[index] = std::fmax(xl[index], lower);
xu[index] = std::fmin(xu[index], upper);
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const double &lower, const std::string access, const int index, const double &upper) {
int dims[] = {<#list viewModel.optimizationVariableDimensions as dim>${dim?c}<#sep>, </#list>};
int cols;
int rows = dims[0];
if (sizeof(dims) <= 1)
cols = 1;
else
cols = dims[1];
if (access.compare("col") == 0) {
for (int i = index; i < xl.size(); i += rows) {
xl[i] = std::fmax(xl[i], lower);
xu[i] = std::fmin(xu[i], upper);
}
} else if (access.compare("row") == 0) {
for (int i = index * cols; i < ((index + 1) * cols); i++) {
xl[i] = std::fmax(xl[i], lower);
xu[i] = std::fmin(xu[i], upper);
}
}
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const colvec &lower, const std::string access, const int index, const double &upper) {
int dims[] = {<#list viewModel.optimizationVariableDimensions as dim>${dim?c}<#sep>, </#list>};
int cols;
int rows = dims[0];
if (sizeof(dims) <= 1)
cols = 1;
else
cols = dims[1];
for (int i = index; i < xl.size(); i += rows) {
xl[i] = std::fmax(xl[i], lower[i]);
xu[i] = std::fmin(xu[i], upper);
}
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const double &lower, const std::string access, const int index, const colvec &upper) {
int dims[] = {<#list viewModel.optimizationVariableDimensions as dim>${dim?c}<#sep>, </#list>};
int cols;
int rows = dims[0];
if (sizeof(dims) <= 1)
cols = 1;
else
cols = dims[1];
for (int i = index; i < xl.size(); i += rows) {
xl[i] = std::fmax(xl[i], lower);
xu[i] = std::fmin(xu[i], upper[i]);
}
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const colvec &lower, const std::string access, const int index, const colvec &upper) {
int dims[] = {<#list viewModel.optimizationVariableDimensions as dim>${dim?c}<#sep>, </#list>};
int cols;
int rows = dims[0];
if (sizeof(dims) <= 1)
cols = 1;
else
cols = dims[1];
for (int i = index; i < xl.size(); i += rows) {
xl[i] = std::fmax(xl[i], lower[i]);
xu[i] = std::fmin(xu[i], upper[i]);
}
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const rowvec &lower, const std::string access, const int index, const double &upper) {
int dims[] = {<#list viewModel.optimizationVariableDimensions as dim>${dim?c}<#sep>, </#list>};
int cols;
int rows = dims[0];
if (sizeof(dims) <= 1)
cols = 1;
else
cols = dims[1];
for (int i = index * cols; i < ((index + 1) * cols); i++) {
xl[i] = std::fmax(xl[i], lower[i]);
xu[i] = std::fmin(xu[i], upper);
}
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const double &lower, const std::string access, const int index, const rowvec &upper) {
int dims[] = {<#list viewModel.optimizationVariableDimensions as dim>${dim?c}<#sep>, </#list>};
int cols;
int rows = dims[0];
if (sizeof(dims) <= 1)
cols = 1;
else
cols = dims[1];
for (int i = index * cols; i < ((index + 1) * cols); i++) {
xl[i] = std::fmax(xl[i], lower);
xu[i] = std::fmin(xu[i], upper[i]);
}
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const rowvec &lower, const std::string access, const int index, const rowvec &upper) {
int dims[] = {<#list viewModel.optimizationVariableDimensions as dim>${dim?c}<#sep>, </#list>};
int cols;
int rows = dims[0];
if (sizeof(dims) <= 1)
cols = 1;
else
cols = dims[1];
for (int i = index * cols; i < ((index + 1) * cols); i++) {
xl[i] = std::fmax(xl[i], lower[i]);
xu[i] = std::fmin(xu[i], upper[i]);
}
};
static void addConstraintOnX(Dvector &xl, Dvector &xu, const double &lower, const std::string access, const double &upper) {
for (int i = 0; i < xl.size(); i++) {
xl[i] = std::fmax(xl[i], lower);
xu[i] = std::fmin(xu[i], upper);
}
};
public:
static bool solveOptimizationProblemIpOpt(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment