public PiecewiseLinearFunction Add(PiecewiseLinearFunction f)
        {
            var g = f.Clone();

            foreach (var x in values)
            {
                g = g.AddPiece(x);
            }

            return(g);
        }
Ejemplo n.º 2
0
        private int getMinPenalty(Route r)
        {
            var l = r.ExtendWithDepots();

            int n = r.Customers.Count;

            PiecewiseLinearFunction[] f = new PiecewiseLinearFunction[r.Customers.Count + 2];
            f[0] = new PiecewiseLinearFunction(); //f = 0

            for (int h = 1; h <= n + 1; ++h)
            {
                //penalty function for current customer
                int customer     = l[h];
                int prevCustomer = l[h - 1];


                PiecewiseLinearFunction ph = PiecewiseLinearFunction.PenaltyFunction(startTime[customer], endTime[customer], penalty);
                int t0 = t[prevCustomer, customer];

                f[h] = f[h - 1].Shift(-t0).Add(ph).Min();
            }

            return(f[n + 1].GetValue(endTime[0]));
        }