Using JaCop in Java to optimize a function

723 Views Asked by At

I'm trying to use the JaCoP library in Java for optimization but I have some trouble translating my functions.

I have a bunch of variables, say: x1 to xn and I have a function using them to output a maximum likelihood estimator (though it could be just any function using theses arguments).

I know how to set constraints on the variables, such as x1+..+xn < C (a constant). What I can't figure out is how to get the solution that maximizes my aforementioned function, as in get x1 to xn where max(a_function(x1,..,xn)).

I'm not posting any code right now since the only thing I'm able to do is set simple constraints on my initial variables as described here. I will update this question as I get better with JaCoP.

If anyone could give me a nudge in the right direction on how to set such a condition it would be appreciated.

Thanks

[EDIT]

Well, I cheated...Since I had Rcaller previously installed in my Java projects I will be using R to compute my maximum likelihood models with constraints. I've been defeated by JaCop. R is much more intuitive to use (from a mathematical perspective) and since Rcaller "talks" pretty well with Java I'm fairly satisfied with the outcome.

1

There are 1 best solutions below

1
On

It nicely hidden, but there's an example containing a cost function.

So IIUIC you need something like

IntVar cost = new IntVar(store, "cost", 0, 1000); 
net.setCostVariable(cost);

In case you don't habe a cost variable, just create it and use constraints to ensure that cost == a_function(x1,..,xn). In case you want to maximize, flip the sign.