数学建模社区-数学中国
标题: E题代码以及UI界面设计 [打印本页]
作者: 478867049 时间: 2014-10-3 17:58
标题: 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[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表格
3 C- `# Q- y6 N) T: [private 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;
}
}
}
2 m' n: S* M9 B% U7 B9 f8 o
; r7 v) N9 q$ c
1 @; ^" h6 g3 A$ F9 c( F7 P' P( \ \. m$ O4 p5 G, F
( h* `% Z2 d0 ?' V) J* w
作者: 深V礼 时间: 2014-10-6 13:48
楼主好厉害的样子啊
作者: wfg786200304 时间: 2014-10-7 10:35
赞。。。。。。。。。。。。。。。。。。。。。。。。。。。。
作者: shuhongwu 时间: 2014-10-7 18:49
乘用车函数
' @/ ?9 `. y- W(1)this.type = height > 1.7 ? 3 : 1; 是否需要更改?高度小于1.7m的有型号I和型号II乘用车,而不单单是型号I乘用车。
, I, n6 Q( N. B2 h# T6 F5 t(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 d9 _( p# I* Z/ [, @' A(3)remainSpace =Tran.real_length - remainCarNotAssgined * real_length;明显的错误,剩余的空间应该是轿运车的长度减去(已放置乘用车数量乘以对应每辆乘用车的长度)。
; g b5 b* c2 G# D/ I& H! j& r/ }8 \( o9 G
轿运车函数
6 @$ R7 K- }( V) Y( ?7 d4 f7 k(1)this.real_length = length + 0.1; 此处0.1是否需要删除?length自增0.1的意义是什么?
! U6 l" e5 y' d- A& M: ]4 d
5 Y5 X$ ^- x4 J& SHash函数映射Excel表格
/ D$ U* _# a& S, v& A/ L J+ `( \(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型。5 W5 k$ F7 g# [
作者: 478867049 时间: 2014-10-7 20:23
shuhongwu 发表于 2014-10-7 18:49
" E$ S$ \* L% k' _) C* c
乘用车函数
: ~) S1 @/ M- P8 {' M" y9 c(1)this.type = height > 1.7 ? 3 : 1; 是否需要更改?高度小于1.7m的有型号I和型号II乘用车 ...
& J# s0 r8 o1 L
请读下题意
作者: 478867049 时间: 2014-10-7 20:27
深V礼 发表于 2014-10-6 13:48
; d" n& `; E& V9 a8 i
楼主好厉害的样子啊
( }* q9 _; D4 R- V2 L还好的,小硕一枚
作者: shuhongwu 时间: 2014-10-7 20:38
478867049 发表于 2014-10-7 20:23 
6 ^$ Q3 b. |% p- ]. O$ K6 J) `请读下题意
# K; u6 m( O2 ~* S6 O受层高限制,高度超过1.7米的乘用车只能装在1-1、1-2型下层。type的可选值为1,2,3。而表达式height > 1.7 ? 3 : 1只提供了两个可选值。我是这么理解二者的差异的,你觉得呢?
作者: 永久的平常心 时间: 2015-7-26 10:58
楼主这是用的什么软件编译的?; d. P9 y& k4 f3 @3 W( {
作者: 阳光照耀的日子 时间: 2016-6-22 07:48
赞一个赞一个
! ^5 b4 @- N7 R( z/ m: u4 b/ \4 e
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) |
Powered by Discuz! X2.5 |