Exemplo n.º 1
0
        //求解按钮点击事件
        private void Solve_Click(object sender, RoutedEventArgs e)
        {
            int numNode = nodes.Count;

            double[] x      = new double[numNode];
            double[] y      = new double[numNode];
            double[] demand = new double[numNode];
            for (int i = 0; i < numNode; ++i)
            {
                x[i]      = nodes[i].X;
                y[i]      = nodes[i].Y;
                demand[i] = nodes[i].Demand;
            }

            int numCar = cars.Count;

            double[] capacity = new double[numCar];
            double[] disLimit = new double[numCar];
            for (int i = 0; i < numCar; ++i)
            {
                capacity[i] = cars[i].Capacity;
                disLimit[i] = cars[i].DisLimit;
            }

            double k1 = 100, k2 = 1, k3 = 1;

            VRPSolver.Solve(x, y, demand, capacity, disLimit, k1, k2, k3, OnFinish, OnError);
        }
Exemplo n.º 2
0
    static public void Run()
    {
        // 10个配送点

        // VRP问题相关数据
        double[] x        = { 12.32, 5.96, 7.73, 10.57, 18.27, 17.55, 18.95, 19.39, 12.75, 11.7, 8.45 };
        double[] y        = { 8.35, 9.39, 7.07, 3.55, 3.97, 6.72, 11.01, 14.33, 14.73, 10.6, 13.48 };
        double[] demand   = { 0.0, 1.4, 1.5, 0.3, 0.5, 1.7, 0.1, 1.3, 1.1, 2.5, 2.2 };
        double[] capacity = { 5.0, 5.0, 5.0, 5.0, 5.0 };
        double[] disLimit = { 20.0, 20.0, 20.0, 20.0, 20.0 };
        double   k1       = 100.0;
        double   k2       = 1.0;
        double   k3       = 1.0;

        // 求解
        VRPSolver.Solve(x, y, demand, capacity, disLimit, k1, k2, k3, OnFinish, OnError);
    }
Exemplo n.º 3
0
    static public void Run()
    {
        // 50个配送点   文件输入

        // 打开文件
        StreamReader reader = new StreamReader("in.txt");
        string       txt    = reader.ReadToEnd();

        char[]   sep   = { ' ', '\t', '\n' };
        string[] input = txt.Split(sep);

        int index = 0;

        // 解析数据
        int numNode = Convert.ToInt32(input[index++]);

        double[] x      = new double[numNode];
        double[] y      = new double[numNode];
        double[] demand = new double[numNode];
        for (int i = 0; i < numNode; ++i)
        {
            x[i]      = Convert.ToDouble(input[index++]);
            y[i]      = Convert.ToDouble(input[index++]);
            demand[i] = Convert.ToDouble(input[index++]);
        }

        int numCar = Convert.ToInt32(input[index++]);

        double[] capacity = new double[numCar];
        double[] disLimit = new double[numCar];
        for (int i = 0; i < numCar; ++i)
        {
            capacity[i] = Convert.ToDouble(input[index++]);
            disLimit[i] = Convert.ToDouble(input[index++]);
        }

        double k1 = Convert.ToDouble(input[index++]);
        double k2 = Convert.ToDouble(input[index++]);
        double k3 = Convert.ToDouble(input[index++]);

        // 求解
        VRPSolver.Solve(x, y, demand, capacity, disLimit, k1, k2, k3, OnFinish, OnError);
    }
Exemplo n.º 4
0
        // 求解
        private void Solve(object parameter)
        {
            CurrentNodeIndex = -1;

            double[] x = new double[Record.Nodes.Count];
            double[] y = new double[Record.Nodes.Count];
            double[] d = new double[Record.Nodes.Count];
            for (int i = 0; i < Record.Nodes.Count; ++i)
            {
                x[i] = Record.Nodes[i].X;
                y[i] = Record.Nodes[i].Y;
                d[i] = Record.Nodes[i].Demand;
            }

            double[] c = new double[Record.Cars.Count];
            double[] m = new double[Record.Cars.Count];
            for (int i = 0; i < Record.Cars.Count; ++i)
            {
                c[i] = Record.Cars[i].WeightLimit;
                m[i] = Record.Cars[i].DisLimit;
            }

            // 弹出loading消息框
            Application.Current.Dispatcher.BeginInvoke(new Action(delegate
            {
                LoadingDialog.Begin("正在求解");
            }));

            // 开启计算线程
            new Thread(delegate()
            {
                //double actualCarSpeed = Record.CarSpeed * (1 - CongestionFactor);
                VRPSolver.Solve(x, y, d, c, m, WTime, WDis, WCar, GenerationCount, Record.CarSpeed, Record.NodeStayTime, OnSolveFinish, OnSolveError);
                Application.Current.Dispatcher.BeginInvoke(new Action(delegate
                {
                    LoadingDialog.End();
                }));
            }).Start();
        }