Decision Optimization

 View Only
Expand all | Collapse all

export all feasible solutions in txt file (docplex.cp)

  • 1.  export all feasible solutions in txt file (docplex.cp)

    Posted Tue March 30, 2021 04:53 PM
    Hello,

    I am trying to export all feasible solutions for my MIP problem from mdl.start_search() in docplex.cp(Python) in a txt file. I have millions of feasible solutions and looping through all solutions and creating a txt file is not an efficient way for me. Is there any faster ways to get all feasible solutions in a text file?
    Here is my code:

    from sys import stdout
    f=open("output_100_112-148_v3.txt","w+") # file name and mode

    siter = mdl.start_search() # Parameters needed to avoid duplicate solutions
    try:

       for j, msol in enumerate(siter):
           f.write(str(j + 1) + " ")
           for i,v in enumerate(x):
               if msol[v]==1:
                    f.write(" " + str(i))

            f.write("\n")

    except CpoNotSupportedException:
        print("I thinThis instance of the solver does not support solution iteration.")

    Thank you

    ------------------------------
    Shahrzad Amoozegar
    ------------------------------

    #DecisionOptimization


  • 2.  RE: export all feasible solutions in txt file (docplex.cp)

    Posted Wed March 31, 2021 02:16 AM
    Hi,

    in https://github.com/AlexFleischerParis/zoodocplex/blob/master/zoocpoenumerate.py

    I used

    siter = mdl.start_search(SearchType='DepthFirst', Workers=1, TimeLimit=100)
    # Parameters needed to avoid duplicate solutions​


    ------------------------------
    [Alex] [Fleischer]
    [EMEA CPLEX Optimization Technical Sales]
    [IBM]
    ------------------------------