Exemplo n.º 1
0
 /// <summary>
 /// Costruttore. throws a DDLNotFoundException if neither CoinOp or CPLEX was founnd.
 /// </summary>
 /// <param name="_w">WriteDelegate</param>
 /// <param name="_problem_name"> nome problema</param>
 /// <param name="N">number of solutions</param>
 /// <param name="verbose">verbose results</param>
 /// <param name="CPLEX">use CPLEX? else CoinOP</param>
 /// <param name="pt">SetCovering or SetPartitioning?</param>
 public PMed3(WriteDelegate _w, uint N, string _problem_name = "PMedProb", bool verbose = false, bool CPLEX = false, eProblemType pt = eProblemType.SetCovering)
     : base(_w, N, verbose)
 {
     fase3         = new Stopwatch();
     MaxIterSecond = 0.0;
     CurDir        = Directory.GetCurrentDirectory();
     InitDLL(_problem_name, CPLEX);
     ProblemType         = pt;
     WrapperVerboseLevel = Wrapper.CoinLogLevel.JustFactorizationsAndMore;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Costruttore
 /// </summary>
 /// <param name="Sol"></param>
 /// <param name="NSol"></param>
 /// <param name="p"></param>
 /// <param name="n"></param>
 /// <param name="pt"></param>
 /// <param name="AddRow"></param>
 public CCS(List <uint>[][] Sol, uint NSol, uint p, uint n, eProblemType pt, bool AddRow = true)
 {
     rowCount     = n;
     colCount     = NSol * p;
     nonZeroCount = NSol * n;
     if (AddRow)
     {
         ConvertToCCS_AddRow(Sol, NSol, p, pt);
     }
     else
     {
         ConvertToCCS(Sol, NSol, p, pt);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Converte la matrice dei costi nel formato CCS
        /// </summary>
        /// <param name="Sol"></param>
        /// <param name="NSol"></param>
        /// <param name="p"></param>
        /// <param name="pt"></param>
        private void ConvertToCCS(List <uint>[][] Sol, uint NSol, uint p, eProblemType pt)
        {
            //int count = 0;
            matrixCount = null;
            matrixBegin = matrixIndex = null;
            char _rowtype_char;

            //matrix count
            //la matrice è simmetrica quindi la sua trasposta è uguale
            //significa che se conto per righe o per colonne è la stessa cosa!
            matrixCount = new int[colCount];
            matrixBegin = new int[colCount + 1];

            //checckare se va bene nel sistema!!!!!! OK
            rhsValues = new double[rowCount];
            switch (pt)
            {
            case eProblemType.SetCovering:
                _rowtype_char = 'G';
                break;

            case eProblemType.SetPartitioning:
                _rowtype_char = 'E';
                break;

            default:
                throw new Exception("CCS.ConvertToCCS : Unknown problem Type.");
            }

            for (int i = 0; i < rowCount; i++)
            {
                rhsValues[i] = 1;
                //rowType += 'G';
                rowType += _rowtype_char;
            }

            //per matrixcount è = alla lunghezza del cluster..
            //per il matrixIndex basta ordinare la soluzione del cluster crescente...
            matrixIndex = new int[nonZeroCount];

            uint[] k;
            int    _i = 0;
            int    mc = 0;

            for (int i = 0; i < NSol; i++)
            {
                for (int j = 0; j < p; j++)
                {
                    matrixCount[mc++] = Sol[i][j].Count;

                    k = Sol[i][j].ToArray();
                    //ordinare k .. un radix sort sarebbe perfetto. ma quicksort va bene lo stesso...
                    Array.Sort(k);

                    for (int k2 = 0; k2 < k.Length; k2++)
                    {
                        matrixIndex[_i++] = (int)k[k2];
                    }
                }
            }

            //matrix values sono gli uni nella matrice
            matrixValues = new double[nonZeroCount];
            for (int i = 0; i < nonZeroCount; i++)
            {
                matrixValues[i] = 1.0;
            }
            //check mindex[0]

            matrixBegin[0] = 0;
            for (int i = 0; i < matrixCount.Length; i++)
            {
                matrixBegin[i + 1] = matrixBegin[i] + matrixCount[i];
            }



#if DEBUG
            //  if (nonZeroCount != count)
            //    throw new Exception("nonZeroCount != count (fine buildCCS)");
#endif
            //nonZeroCount=count;
            //return nonzero;
        }