数学建模社区-数学中国
标题: 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表格) a+ a) ]' N. M. E Y- J( c S3 i% Q: n
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;
}
}
}
. U0 ~4 S/ T; E5 i" G) `+ h
f4 N8 [9 ]9 i$ \9 Q+ D) s9 S6 w |2 b* N1 |1 f" T, T6 E4 M# i3 A
9 }7 W" r+ |9 S
8 V% a- v+ V3 i5 j" x1 i) t
作者: 深V礼 时间: 2014-10-6 13:48
楼主好厉害的样子啊
作者: wfg786200304 时间: 2014-10-7 10:35
赞。。。。。。。。。。。。。。。。。。。。。。。。。。。。
作者: shuhongwu 时间: 2014-10-7 18:49
乘用车函数5 `- ]: r4 K& T: n* U5 G
(1)this.type = height > 1.7 ? 3 : 1; 是否需要更改?高度小于1.7m的有型号I和型号II乘用车,而不单单是型号I乘用车。
6 Q0 ]+ R2 t8 Y. R5 Q4 k(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。5 W) x8 i, S- S" ]4 z
(3)remainSpace =Tran.real_length - remainCarNotAssgined * real_length;明显的错误,剩余的空间应该是轿运车的长度减去(已放置乘用车数量乘以对应每辆乘用车的长度)。
$ I0 P# A. _1 u- w4 d- x/ S4 o0 {+ m/ e0 u" }# V0 F4 O0 B
轿运车函数
) `" M3 W$ F$ s/ M5 D7 B9 S" O B(1)this.real_length = length + 0.1; 此处0.1是否需要删除?length自增0.1的意义是什么?4 Q p) ^% q& L1 }; q8 F
0 t5 Z3 ^$ ]7 c& L% Q
Hash函数映射Excel表格
* P' ~$ K% d, T$ o' i! q* U(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型。
k: W4 @& ^* D- `" n% c
作者: 478867049 时间: 2014-10-7 20:23
shuhongwu 发表于 2014-10-7 18:49 
+ Y& O" D3 G+ X: M6 W5 x, c+ f乘用车函数
2 C. N, [7 t: c v8 d" \(1)this.type = height > 1.7 ? 3 : 1; 是否需要更改?高度小于1.7m的有型号I和型号II乘用车 ...
& z' E( H9 C) T, b6 V' @8 s
请读下题意
作者: 478867049 时间: 2014-10-7 20:27
深V礼 发表于 2014-10-6 13:48 
& G+ m1 W/ \8 O, C' O" R楼主好厉害的样子啊
0 C4 H7 T( z$ T( U7 n$ W+ P% g* ^还好的,小硕一枚
作者: shuhongwu 时间: 2014-10-7 20:38
478867049 发表于 2014-10-7 20:23 
- x- k5 N, U9 U0 C U2 ~5 S请读下题意
0 r8 i2 J [0 A4 S7 t受层高限制,高度超过1.7米的乘用车只能装在1-1、1-2型下层。type的可选值为1,2,3。而表达式height > 1.7 ? 3 : 1只提供了两个可选值。我是这么理解二者的差异的,你觉得呢?
作者: 永久的平常心 时间: 2015-7-26 10:58
楼主这是用的什么软件编译的?* G: S ^; H% H) b8 E; O
作者: 阳光照耀的日子 时间: 2016-6-22 07:48
赞一个赞一个8 Y, ^' ?. m1 d( N& Q y
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) |
Powered by Discuz! X2.5 |