# How to write a callback separation algorithm in java cplex?

 0 Hello to all. I am trying to write a separation algorithm for a branch and boung algorithm. Sadly, like all the people I know who ever had to do this one day, I am not as good in java as in maths, and the web cruelly lacks of examples. My question is "how to tell java to use a constraint?". I have public class SeparateurArbo extends IloCplex.UserCutCallback { // constructor... @Override protected void main() throws IloException { //... I find the constraint IloLinearNumExpr constraint = cplex.linearNumExpr(); // ... IloCplex cplex = new IloCplex(); addLocal(cplex.addGe(constraint,0)); } }  This gives me the worse java error message I ever saw in my entire life : # A fatal error has been detected by the Java Runtime Environment: # # SIGSEGV (0xb) at pc=0x00007ff00e899377, pid=10931, tid=140670663706368 # # JRE version: 6.0_45-b06 # Java VM: Java HotSpot(TM) 64-Bit Server VM (20.45-b01 mixed mode linux-amd64 compressed oops) # Problematic frame: # C [libcplex1260remotejni.so+0x36e377] _dc08c5413c38b61a7a9d7290e4ecded8+0xd27 # # An error report file with more information is saved as: # /home/angilella/workspace/GponOptimizer/hs_err_pid10931.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp  Without the addlocal line, it works perfectly fine, but doesn't add the constraint (so the entire callback becomes useless). I guess I'm not calling this method the proper way, how should I do it? Note that I hate Interfaces and never understood why one would ever create something like that (in this case, IloRange). If possible, I would like a Minimum Java Knowledge Required Answer (MJKRA, a concept that should be more popular). Sorry about being so demanding, but most people answering on forums have no idea what amount of (mostly empirical) knowledge is needed in order to read them. Thanks in advance Provided an address, I am also willing to send a box of chocolate or foie-gras. asked 27 Jan '16, 10:24 V A 11●1●3 accept rate: 0% fbahr ♦ 4.6k●7●17 1 The log says that an "error report file with more information is saved" at /home/angilella/workspace/GponOptimizer/hs_err_pid10931.log. Mind to share? (29 Jan '16, 09:53) fbahr ♦

 1 I'm pretty sure the problem is that you created a brand new IloCplex object (cplex) inside the callback, used it to generate a constraint, and then tried to add that constraint to the original IloCplex object (the one to which the callback is attached). CPLEX ships with source code (including Java code) for a number models, some of which use callbacks. Their location is typically /cplex/examples/src/java/. Take a look at AdMIPex5.java and BendersATSP.java. I posted Java code for a Benders decomposition example (http://orinanobworld.blogspot.com/2014/08/updated-benders-example.html). It uses a LazyConstraintCallback, but the syntax for a UserCutCallback is essentially the same. answered 29 Jan '16, 15:46 Paul Rubin ♦♦ 14.6k●5●13 accept rate: 19% fbahr ♦ 4.6k●7●17
 0 You should use a lazy cut callback or an user cut callback depending on your algorithm (the former omits integer infeasible solution, while the latter omits only fractional infeasible solutions). For an example of the correct implementation of these callbacks, see the BendersATSP.java example in your CPLEX installation folder. Within those callback, the getValue() and getValues() methods retreive the value of decision variables and expressions, provided that they have values (see lines 120 and 157 of the example code). BTW I don't know java, so I cannot help you with more details (I know the details in C++). answered 27 Jan '16, 13:52 Ehsan ♦ 4.8k●3●12●24 accept rate: 16%
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags:

×191
×10
×9
×8
×1