2 using System.Collections.Generic;
7 using System.Threading.Tasks;
11 namespace GUI.IO_Modules
68 locationNames = locNames;
70 locationDictionary = locDic;
71 productDictionary =
new Dictionary<string, int>();
72 DauerBauteillogistik =
new double[locations.Length][];
73 KostenBauteillogistik =
new double[locations.Length][];
74 DauerWerkzeuglogistik =
new double[locations.Length][];
75 KostenWerkzeuglogistik =
new double[locations.Length][];
76 orders =
new List<Order>[locations.Length][];
77 relevantOrders =
new List<Order>[locations.Length][];
87 OleDbConnectionStringBuilder csbuilder =
new OleDbConnectionStringBuilder();
88 csbuilder.Provider =
"Microsoft.ACE.OLEDB.12.0";
89 csbuilder.DataSource = Dir;
90 csbuilder.Add(
"Extended Properties",
"Excel 12.0 Xml");
92 DataTable sheet1 =
new DataTable();
93 using (OleDbConnection connection =
new OleDbConnection(csbuilder.ConnectionString))
96 string sqlQuery =
@"SELECT * FROM [Werkzeuge$]";
97 using (OleDbDataAdapter adapter =
new OleDbDataAdapter(sqlQuery, connection))
101 getToolkitData(sheet1);
105 sheet1 =
new DataTable();
106 using (OleDbConnection connection =
new OleDbConnection(csbuilder.ConnectionString))
109 string sqlQuery =
@"SELECT * FROM [Behälter$]";
110 using (OleDbDataAdapter adapter =
new OleDbDataAdapter(sqlQuery, connection))
112 adapter.Fill(sheet1);
114 getContainerData(sheet1);
118 sheet1 =
new DataTable();
119 using (OleDbConnection connection =
new OleDbConnection(csbuilder.ConnectionString))
122 string sqlQuery =
@"SELECT * FROM [Bestand$]";
123 using (OleDbDataAdapter adapter =
new OleDbDataAdapter(sqlQuery, connection))
125 adapter.Fill(sheet1);
127 getStockData(sheet1);
131 String[] Matrices = {
"Dauer Bauteillogistik",
"Kosten Bauteillogistik",
"Dauer Werkzeuglogistik",
"Kosten Werkzeuglogistik" };
132 foreach (String s
in Matrices)
134 sheet1 =
new DataTable();
135 using (OleDbConnection connection =
new OleDbConnection(csbuilder.ConnectionString))
138 string sqlQuery =
@"SELECT * FROM [" + s +
"$]";
139 using (OleDbDataAdapter adapter =
new OleDbDataAdapter(sqlQuery, connection))
141 adapter.Fill(sheet1);
143 getMatrixData(sheet1, s);
148 foreach (String SheetName
in locationNames)
150 sheet1 =
new DataTable();
151 using (OleDbConnection connection =
new OleDbConnection(csbuilder.ConnectionString))
155 string sqlQuery =
@"SELECT * FROM [Bedarf_" + SheetName +
"$]";
156 using (OleDbDataAdapter adapter =
new OleDbDataAdapter(sqlQuery, connection))
158 adapter.Fill(sheet1);
160 createOrderData(sheet1, SheetName);
173 foreach (DataRow d
in sheet.Rows)
175 int locationIndex = locationDictionary[d[5].ToString()];
178 foreach (String s
in d[2].ToString().Split(
';'))
182 foreach (String s
in d[4].ToString().Split(
';'))
187 t.addInfluencedToolkits(s);
200 FuellgradBehaelter =
new double[sheet.Rows.Count];
201 FuellgradTransportmittel =
new double[sheet.Rows.Count];
202 productNames =
new String[sheet.Rows.Count];
204 foreach (DataRow d
in sheet.Rows)
206 productNames[counter] = d[0].ToString();
207 productDictionary.Add(productNames[counter], counter);
208 FuellgradBehaelter[counter] = Convert.ToDouble(d[1]);
209 FuellgradTransportmittel[counter] = Convert.ToDouble(d[2]);
220 StockOfProdAtLocation =
new double[sheet.Rows.Count][];
221 foreach (DataRow d
in sheet.Rows)
223 StockOfProdAtLocation[productDictionary[d[0].ToString()]] =
new double[sheet.Columns.Count - 1];
224 for (
int i = 1; i < sheet.Columns.Count; i++)
226 StockOfProdAtLocation[productDictionary[d[0].ToString()]][locationDictionary[sheet.Columns[i].ToString()]] = Convert.ToDouble(d[i]);
238 foreach (DataRow d
in sheet.Rows)
240 if (s.Equals(
"Dauer Bauteillogistik"))
242 DauerBauteillogistik[locationDictionary[d[0].ToString()]] =
new double[locations.Length];
243 for (
int i = 1; i < sheet.Columns.Count; i++)
245 DauerBauteillogistik[locationDictionary[d[0].ToString()]][locationDictionary[sheet.Columns[i].ToString()]] = Convert.ToDouble(d[i]);
248 if (s.Equals(
"Kosten Bauteillogistik"))
250 KostenBauteillogistik[locationDictionary[d[0].ToString()]] =
new double[locations.Length];
251 for (
int i = 1; i < sheet.Columns.Count; i++)
253 KostenBauteillogistik[locationDictionary[d[0].ToString()]][locationDictionary[sheet.Columns[i].ToString()]] = Convert.ToDouble(d[i]);
256 if (s.Equals(
"Dauer Werkzeuglogistik"))
258 DauerWerkzeuglogistik[locationDictionary[d[0].ToString()]] =
new double[locations.Length];
259 for (
int i = 1; i < sheet.Columns.Count; i++)
261 DauerWerkzeuglogistik[locationDictionary[d[0].ToString()]][locationDictionary[sheet.Columns[i].ToString()]] = Convert.ToDouble(d[i]);
264 if (s.Equals(
"Kosten Werkzeuglogistik"))
266 KostenWerkzeuglogistik[locationDictionary[d[0].ToString()]] =
new double[locations.Length];
267 for (
int i = 1; i < sheet.Columns.Count; i++)
269 KostenWerkzeuglogistik[locationDictionary[d[0].ToString()]][locationDictionary[sheet.Columns[i].ToString()]] = Convert.ToDouble(d[i]);
275 private void createOrderData(DataTable sheet1,
string sheetName)
278 int locationIndex = locationDictionary[sheetName];
279 orders[locationIndex] =
new List<Order>[productNames.Length];
280 foreach (
int i
in productDictionary.Values)
282 orders[locationIndex][i] =
new List<Order>();
285 foreach (DataRow dr
in sheet1.Rows)
287 String day = dr[0].ToString();
288 if (day.Equals(
""))
break;
289 for (
int i = 1; i < sheet1.Columns.Count; i++)
291 int amount = Convert.ToInt32(dr[i]);
294 orders[locationIndex][productDictionary[sheet1.Columns[i].ToString()]].Add(
new Order(day, amount));
310 StringBuilder sb =
new StringBuilder(5000);
311 sb.Append(getLocations());
312 sb.Append(getProducts());
313 sb.Append(getToolkits());
314 sb.Append(getMachines());
315 sb.Append(getT(d, start, end));
316 sb.Append(getTau(d));
317 sb.Append(getYInit());
319 sb.Append(getDelta());
321 sb.Append(getBeta());
323 sb.Append(getKappa());
324 sb.Append(getSigma());
325 sb.Append(getWdep());
326 sb.Append(getNAndMaxN(start, end));
327 sb.Append(getEpsilon());
328 sb.Append(getGamma(start, d));
331 sb.Append(getEta(d));
332 sb.Append(getAlpha(d));
333 sb.Append(getLambda());
334 sb.Append(getLocOfMachine());
335 sb.Append(getMachinesOfLocation());
336 sb.Append(getWProducer());
339 return sb.ToString();
349 StringBuilder sb =
new StringBuilder(200);
351 usableLocationDictionary =
new Dictionary<string, int>();
354 if (l.CheckState != CheckState.Unchecked)
356 sb.Append(
"\"" + l.Name +
"\", ");
357 usableLocationDictionary.Add(l.Name, locationDictionary[l.Name]);
360 String s = sb.ToString();
361 s = s.TrimEnd(
new char[] {
',',
' ' });
372 StringBuilder sb =
new StringBuilder(300);
374 List<String> ProducedProducts =
new List<String>();
378 if (l.CheckState != CheckState.Unchecked)
384 producableProductDictionary =
new Dictionary<string, int>();
385 foreach (String p
in ProducedProducts)
387 producableProductDictionary.Add(p, productDictionary[p]);
390 foreach (String p
in productNames)
392 sb.Append(
"\"" + p +
"\", ");
394 String s = sb.ToString();
395 s = s.TrimEnd(
new char[] {
',',
' ' });
406 StringBuilder sb =
new StringBuilder(200);
409 usableToolkits =
new List<Toolkit>();
412 if (l.CheckState != CheckState.Unchecked)
416 usableToolkits.Add(t);
417 sb.Append(
"\"" + t.
Name +
"\", ");
421 String s = sb.ToString();
422 s = s.TrimEnd(
new char[] {
',',
' ' });
433 StringBuilder sb =
new StringBuilder(200);
437 if (l.CheckState != CheckState.Unchecked)
441 if (m.CheckState != CheckState.Unchecked)
444 sb.Append(
"\"" + m.Name +
"\", ");
449 String s = sb.ToString();
450 s = s.TrimEnd(
new char[] {
',',
' ' });
461 private String
getT(
double d, DateTime start, DateTime end)
463 StringBuilder sb =
new StringBuilder(200);
466 double hours = end.Subtract(start).TotalHours;
467 int timeslotNumber = (int)(hours / d);
468 for (
int i = 1; i <= timeslotNumber; i++)
472 String s = sb.ToString();
473 s = s.TrimEnd(
new char[] {
',',
' ' });
484 return "tau: " + 60 * d +
"\n";
495 StringBuilder sb =
new StringBuilder(300);
496 sb.Append(
"yInit:[");
499 if (l.CheckState != CheckState.Unchecked)
503 sb.Append(
"(\"" + l.Name +
"\" \"" + t.
Name +
"\") " + 1 +
" ");
507 String s = sb.ToString();
508 s = s.TrimEnd(
new char[] {
',',
' ' });
520 StringBuilder sb =
new StringBuilder(300);
524 if (l.CheckState != CheckState.Unchecked)
526 foreach (String p
in productNames)
528 sb.Append(
"(\"" + l.Name +
"\" \"" + p +
"\") " + l.
Penalty +
" ");
532 String s = sb.ToString();
533 s = s.TrimEnd(
new char[] {
',',
' ' });
545 StringBuilder sb =
new StringBuilder(2000);
546 sb.Append(
"delta:[");
547 foreach (KeyValuePair<String, int> S1
in usableLocationDictionary)
549 foreach (KeyValuePair<String, int> S2
in usableLocationDictionary)
551 foreach (
Toolkit t
in usableToolkits)
553 sb.Append(
"(\"" + S1.Key +
"\" \"" + S2.Key +
"\" \"" + t.
Name +
"\") " + KostenWerkzeuglogistik[S1.Value][S2.Value] +
" ");
557 String s = sb.ToString();
558 s = s.TrimEnd(
new char[] {
',',
' ' });
570 StringBuilder sb =
new StringBuilder(300);
572 foreach (KeyValuePair<String, int> S1
in usableLocationDictionary)
574 foreach (KeyValuePair<String, int> S2
in usableLocationDictionary)
576 sb.Append(
"(\"" + S1.Key +
"\" \"" + S2.Key +
"\") " + KostenBauteillogistik[S1.Value][S2.Value] +
" ");
579 String s = sb.ToString();
580 s = s.TrimEnd(
new char[] {
',',
' ' });
593 StringBuilder sb =
new StringBuilder(300);
595 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
597 foreach (KeyValuePair<String, int> P
in productDictionary)
599 sb.Append(
"(\"" + S.Key +
"\" \"" + P.Key +
"\") " + StockOfProdAtLocation[P.Value][S.Value] +
" ");
602 String s = sb.ToString();
603 s = s.TrimEnd(
new char[] {
',',
' ' });
616 StringBuilder sb =
new StringBuilder(300);
618 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
622 if (m.CheckState != CheckState.Unchecked)
624 foreach (
Toolkit t
in usableToolkits)
631 String s = sb.ToString();
632 s = s.TrimEnd(
new char[] {
',',
' ' });
644 StringBuilder sb =
new StringBuilder(300);
645 sb.Append(
"kappa:[");
646 foreach (KeyValuePair<String, int> P
in productDictionary)
648 sb.Append(
"(\"" + P.Key +
"\") " + FuellgradBehaelter[P.Value] +
" ");
650 String s = sb.ToString();
651 s = s.TrimEnd(
new char[] {
',',
' ' });
663 StringBuilder sb =
new StringBuilder(300);
664 sb.Append(
"sigma:[");
665 foreach (KeyValuePair<String, int> P
in productDictionary)
667 sb.Append(
"(\"" + P.Key +
"\") " + FuellgradTransportmittel[P.Value] +
" ");
669 String s = sb.ToString();
670 s = s.TrimEnd(
new char[] {
',',
' ' });
682 StringBuilder sb =
new StringBuilder(300);
684 foreach (KeyValuePair<String, int> L
in usableLocationDictionary)
691 sb.Append(
"(\"" + t.
Name +
"\") [");
694 sb.Append(
"\"" + ww +
"\" ");
700 String s = sb.ToString();
701 s = s.TrimEnd(
new char[] {
',',
' ' });
718 StringBuilder sb =
new StringBuilder(300);
720 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
722 relevantOrders[S.Value] =
new List<Order>[productNames.Length];
723 foreach (KeyValuePair<String, int> P
in productDictionary)
725 relevantOrders[S.Value][P.Value] =
new List<Order>();
726 foreach (
Order o
in orders[S.Value][P.Value])
731 relevantOrders[S.Value][P.Value].Add(o);
734 sb.Append(
"(\"" + S.Key +
"\" \"" + P.Key +
"\") " + relevantOrders[S.Value][P.Value].Count +
" ");
735 if (maxN < relevantOrders[S.Value][P.Value].Count) maxN = relevantOrders[S.Value][P.Value].Count;
738 String s = sb.ToString();
739 s = s.TrimEnd(
new char[] {
',',
' ' });
740 return s +
"]\n" +
"maxN: " + maxN +
"\n";
751 StringBuilder sb =
new StringBuilder(300);
752 sb.Append(
"epsilon:[");
753 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
755 foreach (KeyValuePair<String, int> P
in productDictionary)
758 foreach (
Order o
in relevantOrders[S.Value][P.Value])
760 sb.Append(
"(\"" + S.Key +
"\" \"" + P.Key +
"\" " + count++ +
") " + o.
Amount +
" ");
764 String s = sb.ToString();
765 s = s.TrimEnd(
new char[] {
',',
' ' });
779 StringBuilder sb =
new StringBuilder(300);
780 sb.Append(
"gamma:[");
781 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
783 foreach (KeyValuePair<String, int> P
in productDictionary)
786 foreach (
Order o
in relevantOrders[S.Value][P.Value])
788 sb.Append(
"(\"" + S.Key +
"\" \"" + P.Key +
"\" " + count++ +
") " + o.
getDueTimeslot(start, d) +
" ");
792 String s = sb.ToString();
793 s = s.TrimEnd(
new char[] {
',',
' ' });
805 StringBuilder sb =
new StringBuilder(300);
807 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
809 foreach (KeyValuePair<String, int> P
in productDictionary)
812 foreach (
Order o
in relevantOrders[S.Value][P.Value])
815 sb.Append(
"(\"" + S.Key +
"\" \"" + P.Key +
"\" " + count++ +
") " + 0 +
" ");
819 String s = sb.ToString();
820 s = s.TrimEnd(
new char[] {
',',
' ' });
832 StringBuilder sb =
new StringBuilder(300);
834 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
838 if (m.CheckState != CheckState.Unchecked)
840 foreach (
Toolkit t
in usableToolkits)
844 sb.Append(
"(\"" + m.Name +
"\" \"" + t.
Name +
"\") " + rho.ToString().Replace(
',',
'.') +
" ");
849 String s = sb.ToString();
850 s = s.TrimEnd(
new char[] {
',',
' ' });
863 StringBuilder sb =
new StringBuilder(2000);
865 foreach (KeyValuePair<String, int> S1
in usableLocationDictionary)
867 foreach (KeyValuePair<String, int> S2
in usableLocationDictionary)
869 foreach (
Toolkit t
in usableToolkits)
871 sb.Append(
"(\"" + S1.Key +
"\" \"" + S2.Key +
"\" \"" + t.
Name +
"\") " + Math.Ceiling(DauerWerkzeuglogistik[S1.Value][S2.Value] / (60 * d)) +
" ");
875 String s = sb.ToString();
876 s = s.TrimEnd(
new char[] {
',',
' ' });
889 StringBuilder sb =
new StringBuilder(300);
890 sb.Append(
"alpha:[");
891 foreach (KeyValuePair<String, int> S1
in usableLocationDictionary)
893 foreach (KeyValuePair<String, int> S2
in usableLocationDictionary)
895 sb.Append(
"(\"" + S1.Key +
"\" \"" + S2.Key +
"\") " + Math.Ceiling(DauerBauteillogistik[S1.Value][S2.Value] / (60 * d)) +
" ");
898 String s = sb.ToString();
899 s = s.TrimEnd(
new char[] {
',',
' ' });
912 return "lambda:" + 0 +
"\n";
923 StringBuilder sb =
new StringBuilder(300);
924 sb.Append(
"LocOfMachine:[");
925 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
929 if (m.CheckState != CheckState.Unchecked)
931 sb.Append(
"(\"" + m.Name +
"\") \"" + S.Key +
"\"" +
" ");
935 String s = sb.ToString();
936 s = s.TrimEnd(
new char[] {
',',
' ' });
948 StringBuilder sb =
new StringBuilder(300);
949 sb.Append(
"MachinesOfLocation:[");
950 foreach (KeyValuePair<String, int> S
in usableLocationDictionary)
954 sb.Append(
"(\"" + S.Key +
"\") [");
957 if (m.CheckState != CheckState.Unchecked)
959 sb.Append(
"\"" + m.Name +
"\" ");
965 String s = sb.ToString();
966 s = s.TrimEnd(
new char[] {
',',
' ' });
978 StringBuilder sb =
new StringBuilder(300);
979 sb.Append(
"WProducer:[");
980 foreach (String p
in productNames)
984 List<String> temp =
new List<string>();
985 foreach (
Toolkit t
in usableToolkits)
991 sb.Append(
"(\"" + p +
"\") [");
992 foreach (String t
in temp)
994 sb.Append(
"\"" + t +
"\" ");
999 String s = sb.ToString();
1000 s = s.TrimEnd(
new char[] {
',',
' ' });
Dictionary< String, int > locationDictionary
Dictionary that maps a location's name to its position in the locations array.
double[][] KostenWerkzeuglogistik
Matrix that contains KostenWerkzeuglogistik data for the model. Index is: [S][S]. ...
List< Order >[][] relevantOrders
List of orders for a product p at location S, that fall into our time horizon. Index is: [S][P]...
String getProducts()
Writes data to set "P". Initializes producableProductDictionary.
String[] locationNames
Array that contains all of the locations' names.
String getMachines()
Writes data to set "M".
LocationCB[] locations
Array that contains all of the locations.
ModelData(String dir, String[] locNames, LocationCB[] loc, Dictionary< String, int > locDic)
Constructor.
String getYInit()
Writes data to array "yInit".
String getMachinesOfLocation()
Writes data to array "MachinesOfLocation".
Dictionary< String, int > producableProductDictionary
Subdictionary that maps a product's name to its position in the product array. Only conatains checked...
String getEpsilon()
Writes data to array "epsilon".
Dictionary< String, int > productDictionary
Dictionary that maps a product's name to its position in the product array.
Dictionary< String, int > usableLocationDictionary
Subdictionary that maps a location's name to its position in the locations array. Only conatains chec...
String getLambda()
Writes data to array "lambda".
String getNAndMaxN(DateTime start, DateTime end)
Writes data to array "N" and field "nMax". Initializes relevantOrders by given time horizon...
String getKhi()
Writes data to array "khi".
String getEta(double d)
Writes data to array "eta".
List< String > extendProducableProducts(List< String > l)
Extends the List of products that can be produced.
List< ProductCB > getProducts()
Grants access to the list of products that belong to the machine.
double[][] KostenBauteillogistik
Matrix that contains KostenBauteillogistik data for the model. Index is: [S][S].
List< Order >[][] orders
List of orders for a product p at location S. Index is: [S][P].
String getLocOfMachine()
Writes data to array "LocOfMachine".
A wrapper class for products.
String getPsi()
Writes data to array "psi".
double[] FuellgradBehaelter
Array that contains FuellgradBehaelter data for the model. Index is P.
String getV(double d)
Writes data to array "v".
A wrapper class for locations.
bool IsDueBetween(DateTime start, DateTime end)
Determins if order is due in a given time interval.
int Amount
How many items are requested.
String Dir
Directory CheckboxCreator reads from.
void getToolkitData(DataTable sheet)
Extract Toolkit data from sheet.
String getAlpha(double d)
Writes data to array "alpha".
double[][] DauerWerkzeuglogistik
Matrix that contains DauerWerkzeuglogistik data for the model. Index is: [S][S].
String toDatString(double d, DateTime start, DateTime end)
Concatenates the array and set strings, suitable for Xpress. Considers only the needed data...
double Bauteilwechselphase
A number that describes the time needed to change toolkits on this machine (in minutes).
String getT(double d, DateTime start, DateTime end)
Writes data to set "T".
String getWdep()
Writes data to array "Wdep".
double[] FuellgradTransportmittel
Array that contains FuellgradTransportmittel data for the model. Index is P.
void getModelData()
Reads all the excel sheets and writes data to respective arrays.
String getTau(double d)
Writes data to set "tau".
String getLocations()
Writes data to set "S". Initilizes usableLocationDictionary.
List< Toolkit > usableToolkits
List that contains all Toolkits.
void getMatrixData(DataTable sheet, String s)
Extract matrix data from sheet.
int getDueTimeslot(DateTime start, double d)
Computes the timeslot when the order is due.
String getRho()
Writes data to array "rho".
void getStockData(DataTable sheet)
Extract stock data from sheet.
double[][] StockOfProdAtLocation
Matrix that contains StockOfProdAtLocation data for the model. Index is: [P][S].
String getToolkits()
Writes data to set "W".
double[][] DauerBauteillogistik
Matrix that contains DauerBauteillogistik data for the model. Index is: [S][S].
String getGamma(DateTime start, double d)
Writes data to array "gamma".
String getWProducer()
Writes data to array "WProducer".
String getNu()
Writes data to array "nu".
A wrapper class for machines.
String getSigma()
Writes data to array "sigma".
String[] productNames
Array that contains all of the products' names.
This class reads all the important data out of an Excel file related to the model.
void getContainerData(DataTable sheet)
Extract container data from sheet.
String getBeta()
Writes data to array "beta".
String getKappa()
Writes data to array "kappa".
double Penalty
A number that describes the estimated penalty for the dalayed production of one product (in Euro)...
List< MachineCB > getMachines()
Grants access to the list of machines that belong to the location.
List< Toolkit > getToolkits()
Grants access to the list of toolkits that belong to the location.
A wrapper class for orders.
String getDelta()
Writes data to array "delta".