add experimental optimo into project

This commit is contained in:
Jonathan Shook 2020-09-10 09:37:07 -05:00
parent 9e4551a7cf
commit 43f41caecd
2 changed files with 14 additions and 6 deletions

View File

@ -7,27 +7,33 @@ public class MVResult {
private final double[] vars; private final double[] vars;
private final MVParams params; private final MVParams params;
private final double[][] datalog;
public MVResult(double[] vars, MVParams params, double[][] datalog) { public MVResult(double[] vars, MVParams params, double[][] datalog) {
this.params = params; this.params = params;
this.vars = vars; this.vars = vars;
this.datalog = datalog;
} }
public double[] getVarArray() { public double[] getVarArray() {
return vars; return vars;
} }
public Map<String,Double> getVarMap() { public double[][] getDatalog() {
Map<String,Double> result = new HashMap<>(params.size()); return datalog;
}
public Map<String, Double> getVars() {
Map<String, Double> result = new HashMap<>(params.size());
for (int i = 0; i < vars.length; i++) { for (int i = 0; i < vars.length; i++) {
result.put(params.get(i).name,vars[i]); result.put(params.get(i).name, vars[i]);
} }
return result; return result;
} }
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int pos=0; int pos = 0;
for (MVParams.MVParam param : params) { for (MVParams.MVParam param : params) {
sb.append(param.name).append("=").append(vars[pos]) sb.append(param.name).append("=").append(vars[pos])
.append(" [").append(param.min).append("..").append(param.max) .append(" [").append(param.min).append("..").append(param.max)

View File

@ -13,7 +13,7 @@ public class PolyglotMultivariateObjectScript implements MultivariateFunction {
private final MVParams params; private final MVParams params;
private final Object function; private final Object function;
private Logger logger; private final Logger logger;
public PolyglotMultivariateObjectScript(Logger logger, MVParams params, Object function) { public PolyglotMultivariateObjectScript(Logger logger, MVParams params, Object function) {
this.logger = logger; this.logger = logger;
@ -37,10 +37,12 @@ public class PolyglotMultivariateObjectScript implements MultivariateFunction {
if (result instanceof Double) { if (result instanceof Double) {
return (Double) result; return (Double) result;
} else if (result instanceof Integer) {
return (double) ((Integer) result);
} else { } else {
throw new RuntimeException( throw new RuntimeException(
"Unable to case result of polyglot function return value as a double:" + "Unable to case result of polyglot function return value as a double:" +
result.getClass().getCanonicalName()+", toString=" + result.toString()); result.getClass().getCanonicalName() + ", toString=" + result.toString());
} }
} }
} }