Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
  • 1.  Custom reversible classes

    Posted Wed June 03, 2020 04:03 AM
    Hello all!

    I am trying to implement a custom constraint using CP Optimizer Extensions (so in C++). In it, I have a class named Arc (my filtering algorithm uses a graph). What would be the best way to go about making Arc reversible? I know that long ago ILOG Solver had a Macro for this (ILCREV(T) which results in a reversible IlcRevT version of T). What would be an equivalent of this Macro in ILOG CPLEX Opt Studio 12.10?

    Arc objects have members of type Arc as well in my code.

    Thank you so much!

    ------------------------------
    Mohammed Najib Haouas
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Custom reversible classes

    Posted Wed June 03, 2020 05:43 AM
    I think the equivalent concept in modern C++ is RAII: you create a wrapper template and in the constructor you store all the state you want to restore and in the destructor you restore the saved state. Also, this website (which is not official IBM documentation) has details about the `ILCREV` macro and even shows to what code the macro expands. From this you get a good idea how to implement such a wrapper template.

    ------------------------------
    Daniel Junglas
    ------------------------------



  • 3.  RE: Custom reversible classes

    Posted Thu June 04, 2020 01:57 AM
    Hello,
    macro ILCREV(T) does not exist any more. Instead, there are classes IlcRevInt, IlcRevFloat, IlcRevBool and IlcRevAny. They can be used as basic building blocks for the Arc class. In particular IlcRevAny can be used to store reversible pointer. Here is the doc: https://www.ibm.com/support/knowledgecenter/SSSA5P_12.10.0/ilog.odms.cplex.help/refcppcplex/html/classes/IlcRevAny.html

    Best regards, Petr

    ------------------------------
    Petr Vilím
    IBM
    ------------------------------



  • 4.  RE: Custom reversible classes

    Posted Sat June 06, 2020 07:00 PM
    Hello Petr,
    while researching, I came across that exact method. I'm expecting to use a static_cast to actually use my Arc objects, do you think that's the way to go or do you have a better way of handling this?

    Thank you all!

    ------------------------------
    Mohammed Najib Haouas
    ------------------------------



  • 5.  RE: Custom reversible classes

    Posted Sun June 07, 2020 04:35 AM
    Hello,

    I'm not sure how exactly you want to use static_cast. It is probably OK: compiler should give you an error if you don't use static_cast correctly. But to give you definite answer I would need a little code sample.

    Best, Petr

    ------------------------------
    Petr Vilím
    IBM
    ------------------------------