Decision Optimization

 View Only
Expand all | Collapse all

How to configure continuous decision variable so that it takes only specified values?

  • 1.  How to configure continuous decision variable so that it takes only specified values?

    Posted Tue April 07, 2020 04:29 AM

    Originally posted by: KeerthivasanC


    I have defined by variable this way:

     

    TP1 = m.integer_var_dict(name = "TP1",keys=project)

     

    Now, I want TP1 to only take the following values - [0,0.5,1,1.5,2]

     

    But I am only able to do something like this in python:

     

    for i in project:
        TP1[i].set_domain([0,1,2,3])

     

    How can I configure TP1 to only take a set of values from a list which has continuous values?

     

    Thanks and Regards


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: How to configure continuous decision variable so that it takes only specified values?

    Posted Tue April 07, 2020 06:18 AM

    Hi,

    let me start again with the bus and zoo story

    https://www.linkedin.com/pulse/making-optimization-simple-python-alex-fleischer/

    You could write

    from docplex.cp.model import CpoModel

    mdl = CpoModel(name='buses')

    #now suppose we can book half a bus and not only complete buses

    scale=2
    scalenbbus40 = mdl.integer_var(0,1000,name='scalenbBus40')
    scalenbbus30 = mdl.integer_var(0,1000,name='scalenbBus30')

    nbbus40= scalenbbus40 / 2
    nbbus30= scalenbbus30 / 2

     

    mdl.add(nbbus40*40 + nbbus30*30 >= 300)
    mdl.minimize(nbbus40*500 + nbbus30*400)

    msol=mdl.solve()

    print(msol[scalenbbus40]/scale," buses 40 seats")
    print(msol[scalenbbus30]/scale," buses 30 seats")

    which gives

    7.5  buses 40 seats
    0.0  buses 30 seats

     


    #CPOptimizer
    #DecisionOptimization