E题代码以及UI界面设计
乘用车函数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; for (int i = 0; i < Tran.Count; i++) { remainSpace =Tran.real_length - remainCarNotAssgined * real_length; } } public void CalcRemainNeedCar(List<Transporter> Tran) { remainNeedTran = new int; 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; maxCarryByLength = new int; carryNeedTran = new int; waste = new double; canCarryByOneTran = newint; 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; 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表格private void ReadExcel_Tran() { //string strFileName = @"C:\Users\clu2\Desktop\result.xlsx"; string strFileName = textBoxInputTran.Text; inputName = strFileName.Split('\\').Split('.'); 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; 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(''); 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 +res2 + res3 + res4; // MessageBox.Show(res1 +" " + res2 + " " + res3 + " " + res4); // int remain1 = res1 +res2 + res3 + res4; // int remain3 = res1 +res2 + res3 + res4; // 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; } }}
楼主好厉害的样子啊 赞。。。。。。。。。。。。。。。。。。。。。。。。。。。。 乘用车函数
(1)this.type = height > 1.7 ? 3 : 1; 是否需要更改?高度小于1.7m的有型号I和型号II乘用车,而不单单是型号I乘用车。
(2)this.real_length = length + 0.1; 是否需要更改为real_length_intermediate = length + 0.1,real_length_edge = length + 0.15,间距存在于前后或者两列乘用车之间,中间部 分每辆乘用车的real_length应该至少自增0.1,边沿部分每辆乘用车的real_length应该至少自增0.15。
(3)remainSpace =Tran.real_length - remainCarNotAssgined * real_length;明显的错误,剩余的空间应该是轿运车的长度减去(已放置乘用车数量乘以对应每辆乘用车的长度)。
轿运车函数
(1)this.real_length = length + 0.1; 此处0.1是否需要删除?length自增0.1的意义是什么?
Hash函数映射Excel表格
(1)g_Tran.Add(newTransporter(2, len, wid, hei, 1, 2, haveCount));应该调整为g_Tran.Add(newTransporter(2, len, wid, hei, 2, 1, haveCount)),因为下、上层分别装载1、2列, 记为1-2型。
shuhongwu 发表于 2014-10-7 18:49 static/image/common/back.gif
乘用车函数
(1)this.type = height > 1.7 ? 3 : 1; 是否需要更改?高度小于1.7m的有型号I和型号II乘用车 ...
请读下题意 深V礼 发表于 2014-10-6 13:48 static/image/common/back.gif
楼主好厉害的样子啊
还好的,小硕一枚 478867049 发表于 2014-10-7 20:23 static/image/common/back.gif
请读下题意
受层高限制,高度超过1.7米的乘用车只能装在1-1、1-2型下层。type的可选值为1,2,3。而表达式height > 1.7 ? 3 : 1只提供了两个可选值。我是这么理解二者的差异的,你觉得呢? 楼主这是用的什么软件编译的?
赞一个赞一个
页:
[1]