Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  read constraints from a file

    Posted 12/01/08 06:35 PM

    Originally posted by: SystemAdmin


    [ncasti said:]

    Hi,

    Could it be possible to read a Constraint from a file?
    Not a difficult one, just something as x+y==17 or x-y==5
    Lets suppose an IloIntVar x, IloIntVar y and IloModel model have been previously created.
    Now I create an ifstream to read some *.txt file and each line of the file has one "simple" constraint.

    Can I use ifstream >> IloExtractable object, IloConstraint object, IloRange object, IloNumExprArg object ?

    Thank you very much for your help.

    Nacho Castiñeiras
    #DecisionOptimization
    #MathematicalProgramming-General


  • 2.  Re: read constraints from a file

    Posted 12/03/08 12:40 AM

    Originally posted by: SystemAdmin


    [prubin said:]

    I don't think it's quite that simple, because there is no obvious way that CPLEX could match the variables in your text expression to the variables in your model.  I think you would have to write a parser that would read the input string, parse it into something like an expression tree, replace symbols like "x" and "y" with the corresponding IloNumVar instances (possibly by matching them against names you assigned to the IloNumVar instances when you created them), then reconstruct the expression in an IloNumExpr.  (Mind you, I'm not positive about this.)
    #DecisionOptimization
    #MathematicalProgramming-General


  • 3.  Re: read constraints from a file

    Posted 12/03/08 01:06 PM

    Originally posted by: SystemAdmin


    [ncasti said:]

    Hi,
    thank you very much for your help.
    I agree totally with you.
    I supposed I will have to make a parser, but first I prefered to ask to the people because perhaps there exists another posibility.

    Thank you again. You have helped me with the Parser steps.

    #DecisionOptimization
    #MathematicalProgramming-General


  • 4.  Re: read constraints from a file

    Posted 12/05/08 01:20 PM

    Originally posted by: SystemAdmin


    [Didier Vidal said:]

    If the LP format is enough for your need, CPLEX reads this format by default. You can find some examples of lp files in <CPLEXDIR>/examples/data


    If you want a more sophisticated modeler language, you might try ILOG OPL wich is just about that (reading constraints from a high level mathematical language). It provides a parser that can be embedded in applications.

    Third solution that I see : XML. The Concert API provides classes to read and write problems in XML (see section optim.concert.xml in the reference manual). However, for large MP models, that format might be quite verbose.

    Didier.

    #DecisionOptimization
    #MathematicalProgramming-General