Exemplo n.º 1
0
        // Each promotion must match
        public int Match()
        {
            // copy list
            LinkedList <Course>    clist_tmp = Course.CopyList(_clist);
            LinkedList <Promotion> plist_tmp = Promotion.CopyList(_plist);
            // result
            LinkedList <Promotion> presult = new LinkedList <Promotion>();

            _cost = -1;

            // recursive method. may take a long time
            RunMatch(clist_tmp, plist_tmp, presult);
            return(_cost);
        }
Exemplo n.º 2
0
        protected void RunMatch(LinkedList <Course> clist, LinkedList <Promotion> plist, LinkedList <Promotion> presult)
        {
            if (plist.Count == 0)
            {
                // end matching
                // calculate cost
                int cost = 0;
                foreach (Promotion p in presult)
                {
                    cost += p._cost;
                }
                foreach (Course c in clist)
                {
                    cost += c._cost;
                }
                // debug
                if (_debug)
                {
                    PrintCPDetail(cost, clist, presult);
                }

                // store result if cheaper
                if ((cost < _cost) || (_cost < 0))
                {
                    _cost = cost;
                    _matchedPromotions = Promotion.CopyList(presult);
                    _matchedCourses    = Course.CopyList(clist);
                }

                return;
            }

            foreach (Promotion p in plist)
            {
                LinkedList <Course>    clist_tmp   = Course.CopyList(clist);
                LinkedList <Promotion> presult_tmp = Promotion.CopyList(presult);

                if (TryMath2Promotion(clist_tmp, p))
                {
                    presult_tmp.AddLast(p);
                }

                // copy
                LinkedList <Promotion> plist_tmp = Promotion.CopyList(plist);
                plist_tmp.Remove(p);
                // recursive
                RunMatch(clist_tmp, plist_tmp, presult_tmp);
            }
        }