|
乘用车函数 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LogisticsPlanningProblem { public class Car { public int quantity; public double length; public double width; public double height; public double real_width; public double real_length; //public double real_length_edge; //public double real_length_intermediate; public int[] maxCarryByLength;//每辆一列最多携带的数量 public int[] carryNeedTran;//整数部分需要运输的数量 public int[] canCarryByOneTran;//每辆整车最多携带的数量 public double[] waste;//一列上浪费的空间 public int pointer;//分配指针,当前指针未分配 public int type; public int[] remainNeedTran; public int remainCarNotAssgined; public double[] remainSpace; public int no; public Car(int no, int type, double length, double width, double height,int quantity) { this.no = no; this.type = height > 1.7 ? 3 : 1; this.real_length = length + 0.1; this.real_width = width + 0.05; this.height = height; this.quantity = quantity; pointer = 0; } public Car(int type, int quantity) { this.type = type; this.quantity = quantity; switch (type) { case 1: length = 4.61; width = 1.7; height = 1.51; break; case 2: length = 3.615; width = 1.605; height = 1.394; break; case 3: length = 4.63; width = 1.785; height = 1.77; break; default: break; } real_width = width + 0.05; real_length = length + 0.1; pointer = 0; //real_length_intermediate = length + 0.1; //real_length_edge = length + 0.05; } public void CalcRemainSpace(List<Transporter> Tran) { remainSpace = new double[Tran.Count]; for (int i = 0; i < Tran.Count; i++) { remainSpace =Tran.real_length - remainCarNotAssgined * real_length; } } public void CalcRemainNeedCar(List<Transporter> Tran) { remainNeedTran = new int[Tran.Count]; remainCarNotAssgined = quantity - pointer;//剩余未分配的车 for (int i = 0; i < Tran.Count; i++) { remainNeedTran =(int)(remainCarNotAssgined / canCarryByOneTran); } CalcRemainSpace(Tran); } //为每种车计算一列最多携带的数量,需要的车的数目 public void CalcMaxCarry(List<Transporter> Tran) { remainNeedTran = new int[Tran.Count]; maxCarryByLength = new int[Tran.Count]; carryNeedTran = new int[Tran.Count]; waste = new double[Tran.Count]; canCarryByOneTran = newint[Tran.Count]; remainCarNotAssgined = quantity - pointer; for (int i = 0; i < Tran.Count;i++) { maxCarryByLength =(int)(Tran.real_length / real_length); if (height < 1.7) { canCarryByOneTran =(maxCarryByLength * (Tran.columnDownCount + Tran.columnUp)); } else { canCarryByOneTran =maxCarryByLength; } carryNeedTran = (int)(quantity/ canCarryByOneTran); waste = Tran.real_length% real_length; remainNeedTran =(int)(remainCarNotAssgined / canCarryByOneTran); } } } } 轿运车函数 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LogisticsPlanningProblem { public class Transporter { public double length; public double width_up; public double width_down; //上下列的数量 public int columnUp; public int columnDownCount; public int quantity; public int remainTran; public List<double[]> Space; public int[] AssignNo; public int type; public double real_length; public int TranUsed; public Transporter(int type, double length, double width_up, doublewidth_down, int columnUp, int columnDown, int quantity) { Space = new List<double[]>(); AssignNo = new int[quantity]; for (int i = 0; i < quantity; i++) { AssignNo = 0; } remainTran = quantity; this.quantity = quantity; this.type = type; this.real_length = length + 0.1; this.width_down = width_down; this.width_up = width_up; this.columnDownCount = columnDown; this.columnUp = columnUp; for (int i = 0; i < quantity; i++) Space.Add(new double[] {real_length, real_length * (int)(type / 3), real_length, real_length *(int)(type / 2) }); } public Transporter(int type) { TranUsed = 0; this.type = type; quantity = 0; switch (type) { case 1: length = 19; width_up = 2.7; width_down = 2.7; columnUp = 1; columnDownCount = 1; break; case 2: length = 24.3; width_up = 3.5; width_down = 2.7; columnUp = 2; columnDownCount = 1; break; case 3: length = 19; width_up = 3.5; width_down = 3.5; columnUp = 2; columnDownCount = 2; break; default: break; } real_length = length + 0.1; } public int MinMod(int[] para) { return 1; } public static void main() { } } } Hash函数映射Excel表格
7 E+ x; G3 N7 k. j9 d% W5 w6 gprivate void ReadExcel_Tran() { //string strFileName = @"C:\Users\clu2\Desktop\result.xlsx"; string strFileName = textBoxInputTran.Text; inputName = strFileName.Split('\\')[strFileName.Split('\\').Length -1].Split('.')[0]; if (!File.Exists(strFileName)) { //MessageBox.Show("Doesnot exist the excel file !"); return; } _Application myExcel = new Microsoft.Office.Interop.Excel.Application(); myExcel.Visible = false; _Workbook myBook = myExcel.Workbooks.Open(strFileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); _Worksheet mySheet = (_Worksheet)myBook.Worksheets[1]; g_Tran = new List<Transporter>(); int pointerNo = 2; while (!(mySheet.get_Range('A' +pointerNo.ToString(), Type.Missing).Value2 == null)) { int no =Convert.ToInt32(mySheet.get_Range('A' + pointerNo.ToString(),Type.Missing).Value2); String type = mySheet.get_Range('B'+ pointerNo.ToString(), Type.Missing).Value2.ToString(); String real_type = type.Split('')[type.Split(' ').Length - 1]; double len =mySheet.get_Range('C' + pointerNo.ToString(), Type.Missing).Value2; double wid =Convert.ToDouble(mySheet.get_Range('D' + pointerNo.ToString(),Type.Missing).Value2); double hei =Convert.ToDouble((mySheet.get_Range('E' + pointerNo.ToString(),Type.Missing).Value2)); int haveCount =Convert.ToInt32((mySheet.get_Range('F' + pointerNo++.ToString(),Type.Missing).Value2)); String t =real_type.Trim().Trim('型'); if (t.Equals("1-1")) { g_Tran.Add(newTransporter(1, len, wid, hei, 1, 1, haveCount)); } else if(t.Equals("1-2")) { g_Tran.Add(newTransporter(2, len, wid, hei, 1, 2, haveCount)); } else { g_Tran.Add(newTransporter(3, len, wid, hei, 2, 2, haveCount)); } } myExcel.Workbooks.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel); GC.Collect(); } #endregion #region Form Operations private void buttonInput_Click(object sender, EventArgs e) { String path = fileSelector(); if (path != null && !path.Equals("")) textBoxInputCar.Text = path; } private void buttonOutput_Click(object sender, EventArgs e) { String path = fileFolderSelector(); if (path != null && !path.Equals("")) textBoxOutput.Text = path; } private String fileSelector() { OpenFileDialog ofd = new OpenFileDialog(); ofd.ShowDialog(); return ofd.FileName; } private String fileFolderSelector() { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.ShowDialog(); return fbd.SelectedPath; } private void buttonCalc_Click(object sender, EventArgs e) { //if (radioButton2.Checked) //{ // int[] val1 = new int[] {(int)numericUpDownA1.Value, (int)numericUpDownA2.Value,(int)numericUpDownA3.Value }; // int[] val2 = new int[] {(int)numericUpDownB1.Value, (int)numericUpDownB2.Value,(int)numericUpDownB3.Value }; // int[] val3 = new int[] {(int)numericUpDownC1.Value, (int)numericUpDownC2.Value,(int)numericUpDownC3.Value }; // int[] val4 = new int[] {(int)numericUpDownD1.Value, (int)numericUpDownD2.Value,(int)numericUpDownD3.Value }; // ht.Add('A' + rowPointer++.ToString(),"A"); // Do(val1); // ht.Add('A' +rowPointer++.ToString(), "B"); // Do(val2); // ht.Add('A' +rowPointer++.ToString(), "C"); // Do(val3); // ht.Add('A' +rowPointer++.ToString(), "D"); // Do(val4); // ht.Add('A' +rowPointer++.ToString(), "以上为方案1,整车方式"); // rowPointer++; // ht.Add('A' +rowPointer++.ToString(), "方案2,卸货方式"); // ht.Add('A' +rowPointer++.ToString(), "A"); // int[] res1 =DoWithoutRemain(val1); // ht.Add('A' +rowPointer++.ToString(), "B"); // int[] res2 =DoWithoutRemain(val2); // ht.Add('A' + rowPointer++.ToString(),"C"); // int[] res3 =DoWithoutRemain(val3); // ht.Add('A' +rowPointer++.ToString(), "D"); // int[] res4 =DoWithoutRemain(val4); // ht.Add('A' + rowPointer++.ToString(),"一起运输"); // int remain0 = res1[0] +res2[0] + res3[0] + res4[0]; // MessageBox.Show(res1[1] +" " + res2[1] + " " + res3[1] + " " + res4[1]); // int remain1 = res1[1] +res2[1] + res3[1] + res4[1]; // int remain3 = res1[2] +res2[2] + res3[2] + res4[2]; // List<Car> ps = newList<Car>(); // Do(new int[] { remain0,remain1, remain3 }); //} //else //{ // Do(); //} ReadExcel_Car(); ReadExcel_Tran(); Question5(); GenerateExcel(); } #endregion private void button1_Click(object sender, EventArgs e) { String path = fileFolderSelector(); if (path != null && !path.Equals("")) textBoxInputTran.Text = path; } } } 9 R6 e2 Z( f" C7 M v
$ T$ T5 a+ g/ q+ ?/ V
4 |9 h9 \: W5 t; E, _' L. i. ~8 |2 ~ c1 R
* J6 ]7 n1 U; I$ \
|