예제 #1
0
 public static void Beep()
 {
     try
     {
         BeepUp.Beep(9000, 1500);
         voic.Speak(read_text, SpeechVoiceSpeakFlags.SVSFDefault);
     }
     catch (Exception ex)
     {
     }
 }
예제 #2
0
        private bool OpenConn()
        {
            bool isOk = false;

            //while (!isOk)
            {
                BeepUp.Beep(16000, 500);
                try
                {
                    myConnection.Open();
                }
                catch (Exception ex)
                {
                    richTextBox1.Text += ex.ToString();
                }

                if (myConnection.State == ConnectionState.Open)
                {
                    isOk = true;
                }
            }
            return(isOk);
        }
예제 #3
0
        public void instances(string path, string SolomonInstancesName)
        {
            #region  数据的录入
            string strconn = path + SolomonInstancesName + ".xlsx;Extended Properties='Excel 12.0;HDR=no;IMEX=1'";
            for (int f = 42; f < 43; f++)                            //开始测试算例-r101
            {
                OleDbConnection Conn = new OleDbConnection(strconn); //读取算例文件名
                Conn.Open();
                OleDbDataAdapter MyCommand1 = new OleDbDataAdapter("SELECT * FROM [DATA$]", strconn);
                DataTable        TripData   = new DataTable();
                try
                {
                    MyCommand1.Fill(TripData);
                }
                catch (System.Exception ex)
                {
                    throw new System.Exception(ex.Message);
                }
                Conn.Close();
                string fileName = TripData.Rows[f][0].ToString();

                //读取顾客数据
                string          strConn = path + fileName + ".xlsx;Extended Properties='Excel 12.0;HDR=no;IMEX=1'";
                OleDbConnection conn    = new OleDbConnection(strConn);
                conn.Open();
                OleDbDataAdapter myCommand1 = new OleDbDataAdapter("SELECT * FROM [sheet1$]", strConn);
                DataTable        tripData   = new DataTable();
                try
                {
                    myCommand1.Fill(tripData);
                }
                catch (System.Exception ex)
                {
                    throw new System.Exception(ex.Message);
                }
                conn.Close();

                List <Request> CustomerSet = new List <Request>();
                double         EndTime     = Convert.ToDouble(tripData.Rows[0][4].ToString());
                Depots[0] = Convert.ToDouble(tripData.Rows[0][1].ToString());
                Depots[1] = Convert.ToDouble(tripData.Rows[0][2].ToString());
                for (int j = 0; j < Length; j++)
                {
                    int     mj       = j;
                    Request tempCust = new Request();
                    tempCust.ID        = mj;
                    tempCust.xCoord    = Convert.ToDouble(tripData.Rows[mj][1].ToString());
                    tempCust.yCoord    = Convert.ToDouble(tripData.Rows[mj][2].ToString());
                    tempCust.earlyTime = Convert.ToDouble(tripData.Rows[mj][3].ToString()) * (24.0 / EndTime);
                    tempCust.lastTime  = Convert.ToDouble(tripData.Rows[mj][4].ToString()) * (24.0 / EndTime);
                    tempCust.cusneed   = Convert.ToInt16(tripData.Rows[mj][5].ToString());
                    CustomerSet.Add(tempCust);
                }
                List <List <double> > Cij = CustomerDistance(CustomerSet); //顾客点距离矩阵
                List <List <double> > Tij = TimeMatrix(CustomerSet, Cij);  //顾客点行驶时间矩阵
                double max1 = 0;
                double min1 = double.MaxValue;
                for (int i = 0; i < Cij.Count; i++)
                {
                    for (int j = 0; j < Cij[0].Count; j++)
                    {
                        if (max1 < Cij[i][j])
                        {
                            max1 = Cij[i][j];
                        }
                        if (min1 > Cij[i][j])
                        {
                            min1 = Cij[i][j];
                        }
                    }
                }
                double max2 = 0;
                double min2 = double.MaxValue;
                for (int i = 0; i < CustomerSet.Count; i++)
                {
                    if (max2 < CustomerSet[i].cusneed)
                    {
                        max2 = CustomerSet[i].cusneed;
                    }
                    if (min2 > CustomerSet[i].cusneed)
                    {
                        min2 = CustomerSet[i].cusneed;
                    }
                }
                #endregion
                double    testResult          = 0;  //计算平均值
                double    totalTime           = 0;  //计算平均耗时
                int       numberOfExperiments = 10; //本算例实验次数
                Stopwatch time = new Stopwatch();
                time.Start();                       //开始计时
                for (int t = 0; t < numberOfExperiments; t++)
                {
                    //算法开始
                    List <Route> solution     = new GreedyInitialSolution(Cij, Tij, Capacity, ServiceTime, CustomerSet, A1, A2, Car_weight, MS).GetSolution(); //初始解
                    List <Route> BestSolution = new ALNS(Cij, Tij, Capacity, ServiceTime, CustomerSet, Coef, A1, A2, Car_weight, MS, min2, max2 - min2, min1, max1 - min1, Iterations).GetSolution(Q, solution);
                    if (!CheckSolution(BestSolution, CustomerSet, Cij, Tij).Equals(true))                                                                      //检查解正误,错误中断报警
                    {
                        BeepUp.Beep(500, 700);
                        Console.ReadLine();
                    }
                    ////输出最终解
                    //    Console.WriteLine("最终解");
                    //for (int i = 0; i < BestSolution.Count; i++)
                    //{
                    //    Console.WriteLine();
                    //    Console.Write("第{0}条route成员为:", i);
                    //    for (int j = 0; j < BestSolution[i].route.Count; j++)
                    //    {
                    //        Console.Write(BestSolution[i].route[j] + "\t");
                    //    }
                    //    Console.WriteLine();
                    //}
                    //Console.WriteLine();
                    testResult += SolutionCost(BestSolution);
                }
                time.Stop();
                //输出本次实验的均值
                Console.WriteLine("解合法!{0}:共实验{1}次,平均耗时{2}s,平均解:{3},平均误差:{4}%", fileName, numberOfExperiments, Math.Round(time.ElapsedMilliseconds / 1000.0 / numberOfExperiments, 2), Math.Round(testResult / numberOfExperiments, 2), Math.Round((Math.Round(testResult / numberOfExperiments, 2) - e) * 100 / e, 2));
            }
        }
예제 #4
0
        void myTimer_Tick(object sender, EventArgs e)
        {
            //throw new NotImplementedException();
            try
            {
                myTable = executeQuery(mySql_1);
                if (num != myTable.Rows.Count)
                {
                    read_text = ReadOrder(myTable, num);
                    Thread MyThread_Beed = new Thread(new ThreadStart(Beep));
                    MyThread_Beed.Start();

                    #region 界面
                    try
                    {
                        string fwq     = myTable.Rows[num]["zoneid"].ToString();
                        string myInfor = "耗时:" + System.DateTime.Now.Hour.ToString() + ":" + System.DateTime.Now.Minute.ToString() + myTable.Rows[num]["OrderNo"].ToString() + "   " + myTable.Rows[num]["cname"].ToString();
                        switch (fwq)
                        {
                        case "58":
                            checkedListBox3.Items.Add(new CheckBox());
                            checkedListBox3.Items[checkedListBox3.Items.Count - 1] = myInfor;
                            break;

                        case "51":
                            checkedListBox1.Items.Add(new CheckBox());
                            checkedListBox1.Items[checkedListBox3.Items.Count - 1] = myInfor;
                            break;

                        case "52":
                            checkedListBox4.Items.Add(new CheckBox());
                            checkedListBox4.Items[checkedListBox3.Items.Count - 1] = myInfor;
                            break;

                        case "55":
                            checkedListBox2.Items.Add(new CheckBox());
                            checkedListBox2.Items[checkedListBox3.Items.Count - 1] = myInfor;
                            break;

                        default:
                            checkedListBox5.Items.Add(new CheckBox());
                            checkedListBox5.Items[checkedListBox3.Items.Count - 1] = myInfor;
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        richTextBox1.Text += ex.ToString();
                    }
                    #endregion

                    num++;
                }
            }
            catch (Exception ex)
            {
                //if (myConnection.State == ConnectionState.Broken || myConnection.State == ConnectionState.Closed)
                {
                    try
                    {
                        myConnection = new MySqlConnection(data_source);
                        myConnection.Open();
                    }
                    catch
                    {
                        BeepUp.Beep(1600, 500);
                        BeepUp.Beep(1600, 500);
                        BeepUp.Beep(1600, 500);
                        voic.Speak("连接中断", SpeechVoiceSpeakFlags.SVSFDefault);
                    }
                }
                richTextBox1.Text += ex.ToString();
            }
        }