コード例 #1
0
ファイル: Iterators.cs プロジェクト: andreasmattas/testcode
        static int sample3()
        {
            int status = 0;

            OplFactory.DebugMode = true;
            OplFactory oplF = new OplFactory();

            try
            {
                OplErrorHandler    errHandler = oplF.CreateOplErrorHandler(Console.Out);
                OplSettings        settings   = oplF.CreateOplSettings(errHandler);
                OplModelSource     src        = oplF.CreateOplModelSourceFromString(getModelTextSample3(), "tuple array iterator");
                OplModelDefinition def        = oplF.CreateOplModelDefinition(src, settings);
                Cplex    cplex = oplF.CreateCplex();
                OplModel opl   = oplF.CreateOplModel(def, cplex);
                opl.Generate();

                // get the string set used to index the array of tuples
                ITupleMap  arrayT = opl.GetElement("arrayT").AsTupleMap();
                ISymbolSet ids    = opl.GetElement("ids").AsSymbolSet();
                // iterate on the index set to retrieve the tuples stored in the array
                IEnumerator it = ids.GetEnumerator();
                while (it.MoveNext())
                {
                    Console.Out.Write("arrayT[" + it.Current + "] = ");
                    IMapIndexArray id = oplF.MapIndexArray(0);
                    id.Add(it.Current.ToString());
                    ITuple t = arrayT.MakeTuple();
                    arrayT.GetAt(id, t);
                    Console.Out.WriteLine(t);
                }
            }
            catch (ILOG.OPL.OplException ex)
            {
                Console.WriteLine(ex.Message);
                status = 1;
            }
            catch (IloException e)
            {
                status = 2;
                Console.Out.WriteLine("### exception: " + e.Message);
            }
            catch (System.Exception ex)
            {
                status = 3;
                Console.Out.WriteLine("### UNEXPECTED ERROR ..." + ex.Message);
            }
            oplF.End();
            return(status);
        }