Originally posted by: Petr Vilím
Hello Jacky,
thinking about it, there is one more catch. Maybe you do in your goal something like this:
IloIntArray array(env);
...
someVariable.setMax(...);
...
array.end();
The problem is that someVariable.setMax triggers constraint propagation that may end up by fail (i.e. the problem is found infeasible). In that case the function setMax never returns. Instead CP Optimizer backtracks and go into a different branch. As the result array.end() is never called and the memory is leaking. Since you say that end() function doesn't work for you, this could be the reason.
So, if you really have to allocate some memory in the goal, the best solution is to free it before affecting the first decision variable. All the other memory should be shared. So, for example, you may allocate your data structure(s), compute what you're going to do, but instead of doing it immediately, store those actions in a shared array. Then destroy your local data structures and only then execute the planned actions from the shared array. When fail occurs then the shared array will remain dirty, but the memory doesn't leak. You just have to keep in mind that the shared array may be dirty each time when the goal starts, so you need to clear it first every time.
Maybe you don't even need the shared array. If you affect only one variable in your goal then just postpone the setMax/Min/StartMin etc until the memory is freed.
Petr
#ConstraintProgramming-General#DecisionOptimization