Forum Numerical Method Optimization
Constrained Optimization
-
ogreyespParticipant 2014-10-09 at 4:47 pm
Hello,
Anyone can help me to understand how work the constraints in SuanShu library. I don’t understand how this example represents this constraint x>=1
* A less than constraint for constrained optimization. 105 */ 106 public static final LessThanConstraints C2 = new GeneralLessThanConstraints( 107 new AbstractBivariateRealFunction() { 108 @Override 109 public double evaluate(double x, double y) { 110 return 1 – x; // x >= 1 111 } 112 });
If a have the following constraint:
q1+q2+….+qn<=1
How I can implement this in the SuanShu library?
Best regards,
Oscar
- This topic was modified 2 years, 3 months ago by webmaster.
-
hao.dingParticipant 2014-10-10 at 3:52 am
Hi,
q1+q2+…+qn<=1 is a linear constraints, you can construct such a linear constraint in SuanShu use the following codes:
Matrix A = new DenseMatrix(1, n); for (int i = 1; i <= n; i++) { A.set(1, i, 1.); } //A = [1,1,…,1] Vector b = new DenseVector(1.); // b = [1] LinearLessThanConstraints less = new LinearLessThanConstraints(A, b); -
hao.dingParticipant 2014-10-10 at 5:00 am
In the example you mentioned, it represents the constraint x>=1 because it evaluates 1-x, and when the evaluation is smaller than 0, the constraint is satisfied.
Therefore when you want to construct a constraint Ax>=b, in the evaluation part you should return b-AX.
- This reply was modified 2 years, 3 months ago by hao.ding.
-
ogreyespParticipant 2014-10-10 at 8:42 am
Thanks you very much for your quickly response.
Best regards,
Oscar
-
ogreyespParticipant 2014-10-14 at 6:04 pm
Hello,
I’ have defined an objetive function (it has some complexity) and 4 linear constraints (they are very simple). So, I have put the following code, as same as the example that comes with the SuanShu library:
/// double gamma = 1e30; double epsilon = 1e-8; int maxIterations = 200;PenaltyMethodMinimizer optim = new PenaltyMethodMinimizer( PenaltyMethodMinimizer.DEFAULT_PENALTY_FUNCTION_FACTORY, gamma, new BFGSMinimizer(false, epsilon, maxIterations));
IterativeMinimizer<Vector> minimizer = optim.solve(problem);Vector xmin = minimizer.search(new DenseVector(q));//////////
The problem that i have is the following: The BFGSMinimizer never outs from the 1 iteration, i.e it still executing in the 1st iteration of the BFGS algorithm and does’nt stop. I printed the value of the defined objetive function each time that it is evaluated for BFGS and for example this is the continiusly stream that appears in the screen:
16079.194741736539 16079.194729964249 16079.194738279763 16079.194733421027 16079.194726798403 16079.194744902386 16079.194737157148 16079.19473454364 …. ….. …. …. an go on.
Anyone have an idea of why the BFGS algorithm does not stop.
Best regards,
Oscar
-
hao.dingParticipant 2014-10-15 at 4:18 am
Hi,
It is hard to know the problem if the objective function, constraints and data are unknown. It would be helpful if you can provide them. From the information you provided currently, my guesses are:
BFGS method is not good when the starting points are far from optimal point. Because it moves very slow. You can try other optimization method first, and use the results as starting points for BFGS to refine the results.
Another possibility is that the starting point is a local minimum but not a global minimum. So BFGS cannot move away from the starting points. You may try other starting points.
-
webmasterKeymaster 2014-10-17 at 12:03 pm
Our site should allow uploading file types with extensions such as *.java, *.zip, *.docx, *.xlsx. Please try again.
- This reply was modified 2 years, 3 months ago by webmaster.
-
ogreyespParticipant 2014-10-17 at 4:08 pm
-
ogreyespParticipant 2014-10-17 at 4:08 pm
The codes were uploaded
-
hao.dingParticipant 2014-10-20 at 5:06 am
Hi,
I took a look at your constraint program, and found that your first, second and fourth constraints are same. First constraint: sum(q)<=batch Second constraint: sum(q)<= d.size/2 (although you loop i from 1 to split point, but sum is sum(d)) Fourth constraint: sum(q)<=d.size
Would you please let me know if I understand your constraints correctly? Also may I have your data and the program where you call QuasiNewtonOptimizer so I can debug your problem? Thanks.
-
ogreyespParticipant 2014-10-20 at 7:38 am
Hi Hao Ding.
Thanks you soo much for your help. I have restricted the problem only to the first and third constraint and the issue was resolved. You are right, the first, second and fourth constraint express the same.
Although, the BFGS method still runs ver slow, maybe due to the complexity of the objetive function. I will follow your past recomendation “try other optimization method first, and use the results as starting points for BFGS to refine the results.”
Again, thanks very much for your help.
Best regards,
Oscar