Decision Optimization

Decision Optimization

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

 View Only
  • 1.  How to use Cplex As A Service in Watson Studio

    Posted Thu October 31, 2024 04:36 AM

    Hi all,

    I have been working with CPLEX for some years for a new platform we are developing. We bought some license 12.10 to use CPLEX in a distributed parallel optimization (here the logic)

    Then IBM released the new CPLEX 20.X (now 22) and talking with them I understand that now it should be possible to use Cplex as a Service inside Watson Studio. So I am imagining to use Cplex not calling my remote VM but some online machines (provided by IBM) to resolve my problems.

    I created a free account for Watson Studio but I am really struggling with this because I have looked for the mechanism but I did not understand if it works this way and how it should work if it is possible.

    I have found this example.

    The questions: is it possible to create a Cplex problem locally (pyomo + python) and send it to a Cplex as a service to receive the results like I did with the distributed parallel optimization? Is it the right way or am I missing something?

    Thank you all for your time.

    Best Regards

    Riccardo



    ------------------------------
    Riccardo Barilli
    Product Owner Software
    ------------------------------


  • 2.  RE: How to use Cplex As A Service in Watson Studio

    Posted Mon November 04, 2024 05:14 AM

    Hi,

    in watsonstudio the python API for CPLEX is docplex so what you can do is generate your model with pyomo and then import it through docplex like in https://github.com/AlexFleischerParis/zoodocplex/blob/master/zoopyomogenerateanddocplexsolve.py

    Or you can generate your .sav file with pyomo and then send this .sav file to the IBM Cloud

    See https://medium.com/@AlainChabrier/cplex-and-cpo-file-formats-with-do-experiments-in-cloud-pak-for-data-a2abf93c9c18



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 3.  RE: How to use Cplex As A Service in Watson Studio

    Posted Tue November 05, 2024 09:42 AM

    Hi Alex,

    I really appreciate the help. I managed to create a mlp file, load it manually on cloud park and solve it. I would like to ask you something else: is it possible to load the model automatically through a Rest API on Cloud Park or Watson? We are running multiple optimisation every 15 min or every hour and, of course, the manual loading is not a possibility.

    Thank you

    Riccardo



    ------------------------------
    Riccardo Barilli
    Product Owner Software
    ------------------------------



  • 4.  RE: How to use Cplex As A Service in Watson Studio

    Posted Tue November 05, 2024 09:56 AM

    Hi,

    indeed you can do the same with APIs

    https://medium.com/@AlainChabrier/solve-lp-models-with-do-for-wml-5299da95c5ad

    regards



    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------



  • 5.  RE: How to use Cplex As A Service in Watson Studio

    Posted Fri November 08, 2024 10:59 AM

    Hi Alex,

    we managed to run a job on Watson in an automatic way! thank you again

    {'CPLEXSolution': {'@version': '1.2', 'header': {'@writeLevel': '1', '@solutionName': 'incumbent', '@solutionTypeString': 'primal', '@problemName': 'model_opt.lp', '@solutionStatusString': 'integer optimal, tolerance', '@solutionStatusValue': '102', '@dualFeasible': '0', '@primalFeasible': '1', '@solutionTypeValue': '3', '@solutionMethodString': 'mip', '@solutionIndex': '-1', '@MIPNodes': '0', '@MIPIterations': '1266', '@objectiveValue': '98.846203769477228'}, 'quality': {'@epRHS': '9.9999999999999995e-07', '@epInt': '1.0000000000000001e-05', '@maxX': '9000', '@maxPrimalInfeas': '4.0971871302361387e-08', '@maxSlack': '10000000', '@maxIntInfeas': '6.0825600000001143e-09'}, 'linearConstraints': {'constraint': [{'@slack': '1.4210854715202004e-14', '@name': 'c_e_opex_calc_', '@index': '0'}, {'@slack': '0', '@name': 'c_e_penalty_withdrawn_', '@index': '1'}, {'@slack': '0', '@name': 'c_e_penalty_slack_calc_', '@index': '2'}, {'@slack': '0', '@name': 'c_e_imbalance_penalty_calc_', '@index': '...52'}, {'@slack': '0.52590000000054715', '@name': 'c_u_EX_b(ESSA_EX_0001)_max_withdrawn_calc(49)_', '@index': '53'}, {'@slack': '0.52590000000054715', '@name': 'c_u_EX_b(ESSA_EX_0001)_max_withdrawn_calc(50)_', '@index': '54'}, {'@slack': '0.52590000000054715', '@name': 'c_u_EX_b(ESSA_EX_0001)_max_withdrawn_calc(51)_', '@index': '55'}, {'@slack': '0.52590000000054715', '@name': 'c_u_EX_b(ESSA_EX_0001)_max_withdrawn_calc(52)_', '@index': '56'}, {'@slack': '8059.7299999999996', '@name': 'c_u_EX_b(ESSA_EX_0001)_max_withdrawn_calc(53)_', '@index': '57'}, {'@slack': '8059.7299999999996', '@name': 'c_u_EX_b(ESSA_EX_0001)_max_wi ...

    this is a json view of the results.

    May I ask you if there is a simple way to load it in the Pyomo ConcreteModel in order to use the same code we are using with the distributed cplex?

    Usually we do this and then we parse the pyomo instance to get the results

    opt = pyopt.SolverFactory("cplex_direct", solver_io='python')

    self.instance_results = opt.solve(self.instance_ems_model, symbolic_solver_labels=True, tee=True)

    thank you

    Riccardo



    ------------------------------
    Riccardo Barilli
    Product Owner Software
    ------------------------------



  • 6.  RE: How to use Cplex As A Service in Watson Studio

    Posted Mon November 11, 2024 01:06 PM

    In https://dataplatform.cloud.ibm.com/analytics/notebooks/v2/9e8c8847-b67b-432b-bc69-f9377e365317/view?access_token=9835723411fe0e1d8fe2065f31a088f6e4a5d02e10398398ac0dddb3b4b0faea

    you have an example of how to get the json solution

    # GET SOLUTION
    
    import json
    
    mylog("Download solution")
    
    file = cos_client.Object(COS_BUCKET, 'solution.json').get()
    
    solution = json.loads(file["Body"].read().decode("utf-8"))
    
    print ('Objective Value: ' + solution['CPLEXSolution']['header']['objectiveValue'])
    #diet1.lp Objective Value: 2.6904091716962637


    ------------------------------
    [Alex] [Fleischer]
    [Data and AI Technical Sales]
    [IBM]
    ------------------------------