Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  How to stop PrintConflict()?

    Posted 11/24/14 11:24 PM

    Originally posted by: OptimisationSpecialist


    We have some C# code which stops PrintConflict() after a specified time limit (i.e. the file is too big).  The only problem is that the program hangs (it works fine if PrintConflict is small and completes).  We are using a SOAP Webservice and Internet Information Services.  I am building my knowledge about this configuration.

    Is it possible to stop PrintConflict programmatically without hanging the application?  What is the recommended approach?

    I know that Thread.Suspend() is obsolete.  The code below was provided by a contractor.

     

                                else
                                {
    
                                    //printConflictDelegate = new PrintConflictDelegate(runConfig.GetOplModel().PrintConflict);
                                    //printConflictDelegate.BeginInvoke(writeConflictFile);
    
                                    System.Threading.Thread printConflictThread = new System.Threading.Thread(() => runConfig.GetOplModel().PrintConflict(writeConflictFile));
    
                                    printConflictThread.Start();
    
                                    while (!printConflictThread.IsAlive) ;//wait until printConflictThread commenced
    
                                    AddDetailToProcessLog(System.Reflection.MethodBase.GetCurrentMethod().Name, "Printing conflict file with time limit of " + printConflictFileTimeLimit + " seconds");
    
                                    for (int sec = 0; sec < printConflictFileTimeLimit; sec++)
                                    {
                                        System.Threading.Thread.Sleep(1000); //sleep with a limit
    
                                        if (!printConflictThread.IsAlive) //back to work if printConflictThread is done
                                        {
                                            AddDetailToProcessLog(System.Reflection.MethodBase.GetCurrentMethod().Name, "Conflict file printing finished ahead from the time limit");
                                            break;
                                        }
                                    }
    
                                    if (printConflictThread.IsAlive)//if the printConflictThread is not yet done but sleep limit is reached... abort!
                                    {
                                        AddDetailToProcessLog(System.Reflection.MethodBase.GetCurrentMethod().Name, "Conflict file printing reached the time limit");
                                        AddDetailToProcessLog(System.Reflection.MethodBase.GetCurrentMethod().Name, "Forcing the thread to shutdown. This will throw an error.");
                                        AddDetailToProcessLog(System.Reflection.MethodBase.GetCurrentMethod().Name, "Process Exited");
                                        printConflictThread.Suspend();
                                    }
    
                                    writeConflictFile.Flush();
                                    writeConflictFile.Close();
                                    writeConflictFile = null;
                                }
                                #endregion thread branch
    

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: How to stop PrintConflict()?

    Posted 11/25/14 11:00 AM

    hi

    have you tried to iterate on conflicts instead of printing all conflicts ?

    You have an example at

    opl\examples\opl\conflictIterator

    in C# you may use

    
    public 
    OplConflictIterator 
    GetConflictIterator()
    

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: How to stop PrintConflict()?

    Posted 11/25/14 05:53 PM

    Originally posted by: OptimisationSpecialist


    We have cplex v12.3 and I have found that OplConflictIterator is missing first(), hasNext(), Next(), getStatus().  These are in the 12.6 Help and I think I need them to manually iterate.

    Should hasNext() be called before first() to check whether there is a conlict or does the iterator start with the first conflict?

    Which method returns the current conflict?  Is it ToString()?  What does getExtractable() do?

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: How to stop PrintConflict()?

    Posted 11/25/14 03:32 PM

    Originally posted by: OptimisationSpecialist


    Thanks.  I'll give that a go.

     

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer