Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Read and Edit LP File in OPL

    Posted Tue June 20, 2023 10:19 AM

    A separate team is generating an .lp file and we are wanting to pick it up and run variants of the problem by editing variable upper and lower bounds where we know the variable names, but not the indexes which need edited.

    I see in Python, you can use cplex.variables.get_names() to get variable names after reading in the .lp file, but is there a similar method in the OPL IDE?  Java is another alternative if it can't be done through the IDE.

    Thanks.

    Matthew Colvin



    ------------------------------
    Matthew Colvin
    ------------------------------


  • 2.  RE: Read and Edit LP File in OPL

    Posted Tue June 20, 2023 11:22 AM

    I don't know if it can be done in the IDE, but in Java you can iterate over the elements of a model. The method IloNumVar.getName() will let you get the name of a variable. I posted some sample code in a rather old blog post, but I think the syntax has not changed.



    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 3.  RE: Read and Edit LP File in OPL

    Posted Tue June 20, 2023 11:39 AM

    Thanks!

    While the IDE would be preferable just to help other coworkers out, I can work with this.



    ------------------------------
    Matthew Colvin
    ------------------------------



  • 4.  RE: Read and Edit LP File in OPL

    Posted Thu June 22, 2023 03:06 AM

    Hi,

    at https://github.com/AlexFleischerParis/howtowithopl/blob/master/importlpfile.mod you can see a small example

    main
    {
      cplex.importModel("zoo.lp");
      cplex.solve();
      writeln("objective = ",cplex.getObjValue());
      
    }

    and in the IDE you can see lp files



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



  • 5.  RE: Read and Edit LP File in OPL

    Posted Thu June 22, 2023 10:09 AM

    I had seen the ability to solve an LP in the IDE, but our problem is that a different group generates the .lp file and we are picking it up from a repository and doing "what-if" analysis requiring manipulating variables.  

    We know the naming convention, so can identify by name what needs adjusted, but the indexing will vary by lp file based on business.

    We have put together something in Java now, but would have preferred to do so in the IDE for a wider audience in the company.

    I do appreciate the help though as I wasn't the clearest in my question or use case.



    ------------------------------
    Matthew Colvin
    ------------------------------