Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Managing infeasibility from .Net API

    Posted 02/21/11 05:48 PM

    Originally posted by: Marcelo.cl


    Hi to all, I'm new here and I would like to ask for your help.

    I have a MIP model.
    Certain constraits entered by the user could be impossible to be accomplished.
    So, I need to manage this infeasibility by ignoring these type of constraints.
    Reading this forum, I found I can use RefineConflict + GetConflict.
    I'm using in this way:

    opl.Cplex.RefineConflict(constraints, preferences)
    For i As Integer = 0 To cantRestricciones - 1
    Console.WriteLine(opl.Cplex.GetConflict(constraints(i)).ToString())
    Next

    So, I can know which constrints make my model unfeasible.
    But now, i want to discard these constarints and continue solving my model.
    One way to do that is to write again the data file and run the model again with the new data.

    But I'm wondering if there is any way to "delete" or relax the unfeasible constraints and continue running the same execution that was unfeasible before, in order to gain time, and do not start over.

    I'm working with these software:
    • IBM ILOG OPL IDE Versión: 6.3
    IBM ILOG CPLEX 12.1.0
    IBM ILOG CP Optimizer 2.3
    IBM ILOG Concert Technology 2.9
    • Visual Studio 2005 with Visual Basic (.Net Framework 2.0)

    I really would appreciate some help.
    Thanks in advance.

    This is the code I'm working with. It's not finished yet, but is the main part.

    Dim status As Integer = 127
    OplFactory.DebugMode = False
    Dim oplF As OplFactory = New OplFactory
    Dim errorHandler As OplErrorHandler = oplF.CreateOplErrorHandler()
    Dim modelSource As OplModelSource = oplF.CreateOplModelSource(RutaModeloAsignacionMes)
    Dim settings As OplSettings = oplF.CreateOplSettings(errorHandler)
    Dim def As OplModelDefinition = oplF.CreateOplModelDefinition(modelSource, settings)
    Dim cplex As Cplex = oplF.CreateCplex()
    cplex.SetOut(Nothing)
    cplex.SetParam(ILOG.CPLEX.Cplex.DoubleParam.TiLim, 60 * 1) ''--> minutos de time limit
    Dim opl As OplModel = oplF.CreateOplModel(def, cplex)
    Dim dataSource As OplDataSource = oplF.CreateOplDataSource(dataFile)
    opl.AddDataSource(dataSource)
    opl.Generate()

    Dim isConSolucion As Boolean = cplex.Solve()
    While isConSolucion = False And cplex.GetCplexStatus.ToString = "AbortTimeLim"
    isConSolucion = cplex.Solve()
    End While

    If isConSolucion Then
    Console.Out.WriteLine("OBJECTIVE: " + Str(opl.Cplex.ObjValue))
    status = 0
    Else
    Console.WriteLine("No solution")
    status = 1

    '''''''''''''''''''''''''''''''
    'conflicts
    Console.Out.WriteLine("There are conflicts.....")

    Dim restricciones As IConstraintMap = opl.GetElement("ctRestLibre").AsConstraintMap
    Dim setRestricciones As ITupleSet = opl.GetElement("restriccionesLibre").AsTupleSet
    Dim itRest As IEnumerator = setRestricciones.GetEnumerator
    Dim cantRestricciones As Integer = setRestricciones.Size
    Dim constraints(cantRestricciones - 1) As ILOG.Concert.IConstraint
    Dim preferences(cantRestricciones - 1) As Double

    Dim ixRest As Integer = 0
    While itRest.MoveNext
    Dim t As ITuple = itRest.Current
    preferences(ixRest) = ixRest + 1
    constraints(ixRest) = restricciones.Get(t)
    ixRest = ixRest + 1
    End While

    opl.Cplex.RefineConflict(constraints, preferences)

    For i As Integer = 0 To cantRestricciones - 1
    Console.WriteLine(opl.Cplex.GetConflict(constraints(i)).ToString())
    Next

    End If
    oplF.End()
    Environment.ExitCode = status
    Return isConSolucion
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Managing infeasibility from .Net API

    Posted 02/22/11 02:57 AM

    Originally posted by: SystemAdmin


    I am not a .NET expert but I would expect something like the following to work:
    opl.Cplex.RefineConflict(constraints, preferences)
    For i As Integer = 0 To cantRestricciones - 1
        If opl.Cplex.getConflict(constraints(i)) == Cplex.ConflictStatus.Member Then
           opl.Cplex.Remove(constraints(i))
        End If
    Next
    

    This should remove all constraints that are part of the conflict. I am not sure if removing a constraint invalidates the conflict stored in the Cplex instance. So maybe it is better to first collect a list of constraints to be removed. Then write another loop that removes all collected constraints in one shot (or collect the constraints in an array and use the Cplex.Remove() overload that accepts an array).

    Did you consider using Cplex.Feasopt()? This computes a minimal relaxation of your model that renders the model feasible. Please also refer to the user manual for further details about feasopt.
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Managing infeasibility from .Net API

    Posted 02/24/11 04:03 PM

    Originally posted by: Marcelo.cl


    Thanks for your answer.

    I tried to remove and solve again.

    opl.Cplex.RefineConflict(constraints, preferences)
    For i As Integer = 0 To cantRestricciones - 1
    If opl.Cplex.getConflict(constraints(i)) == Cplex.ConflictStatus.Member Then
    opl.Cplex.Remove(constraints(i))
    End If
    Next
    cplex.Solve()

    But the with the last sentence (cplex.Solve) the aplicatiton doesnt try to solve again and continues on next line.
    I guess the model has an infeasible status or something.

    I haven't considered Cplex.Feasopt(), I will do. Thanks.
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Managing infeasibility from .Net API

    Posted 02/22/11 02:20 PM

    Originally posted by: GuangFeng


    A shortcut to print conflicts through OPL .NET API is OplModel.PrintConflict(). You do not even need to call opl.Cplex.RefineConflict(constraints, preferences). The labeled constraints will be passed to Cplex for conflict refinement automatically.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Managing infeasibility from .Net API

    Posted 02/24/11 04:08 PM

    Originally posted by: Marcelo.cl


    > GuangFeng wrote:
    > A shortcut to print conflicts through OPL .NET API is OplModel.PrintConflict(). You do not even need to call opl.Cplex.RefineConflict(constraints, preferences). The labeled constraints will be passed to Cplex for conflict refinement automatically.
    Hi. Yes, I tried to use PrintConflict.
    I labeled my constraints (array of lables).
    But when I use PrintConflict in .net API it displays a message without constraints labels. Something like "<unnamed constraint> is in conflict".
    It's strange, because when I use PrintConflict in the main() of the model, it displays conflicts correctly.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Managing infeasibility from .Net API

    Posted 02/24/11 10:23 PM

    Originally posted by: GuangFeng


    Try something like below before calling OplModel.PrintConflict()

    OplModel.Settings.IsWithNames=true;
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Managing infeasibility from .Net API

    Posted 02/25/11 04:24 PM

    Originally posted by: Marcelo.cl


    > GuangFeng wrote:
    > Try something like below before calling OplModel.PrintConflict()
    >
    > OplModel.Settings.IsWithNames=true;

    Thanks. I tried but I still getting message: " (unnamed constraint) " is in conflict.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Managing infeasibility from .Net API

    Posted 02/25/11 04:59 PM

    Originally posted by: Marcelo.cl


    Hi, I´m still working with RefineConflict + GetConflict and now i'am receiving this message "CPLEX Error 1719: Conflict is not available." when I call GetConflict (constraints)

    I figured out that if opl.Cplex.GetStatus = Infeasible, then I get the conflicts with no problems

    But, if opl.Cplex.GetStatus = InfeasibleOrUnbounded, then I get message CPLEX Error 1719: Conflict is not available.
    In addition, when status=InfeasibleOrUnbounded I get "No conflicts available" when I call PrintConflict.

    I'm absolutely sure there are conflicts due to some constraints, because if I delete the data related to those constraints, the model is feasible and i get a solution.

    Does anyone know how I can get the conflicts when status is InfeasibleOrUnbounded, or what can I do?

    Thanks in advance.
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Managing infeasibility from .Net API

    Posted 02/26/11 02:16 AM

    Originally posted by: Marcelo.cl


    Hi. Another 2 questions:

    1) With some data, after RefineConflict, all conflicts have status PossibleMember, so I don't know how to start removing constraints. In preferences I assign only positive values between 400 and 1000.

    2) How can I set objective function to 0 (I read this is a way to get Infeasible status instead of InfeasibleOrUnbounded status)

    Thanks in advance
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Managing infeasibility from .Net API

    Posted 03/01/11 01:27 AM

    Originally posted by: GuangFeng


    A few thoughts:
    1. I forgot to mention that the place you sets IsWithNames matters. It is best if you set it immediately after you create OplSettings object.
    2. Turning off presolve might give you additional information to diagnose InfeasibleOrUnbounded status. However, as OPL only work on labeled constraints. If the infeasibility is caused by unlabeled constraints, you need to label the constraints first or use CPLEX API. You can check the documentation on the benefits of constraint labeling here.

    You should also perform an upgrade to CPLEX Optimization Studio 12.2, in case there were bugs involved.
    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Managing infeasibility from .Net API

    Posted 03/01/11 09:14 AM

    Originally posted by: Marcelo.cl


    Thanks GuangFeng.

    I set IsWithNames as you said and it works perfect. Thanks a lot.

    About InfeasibleOrUnbounded status, I choose to set objective to 0 ( opl.Objective.ClearExpr() ), so the status is Infeasible now. Thanks again.
    #CPLEXOptimizers
    #DecisionOptimization