Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Forms;
- using System.Data;
- using System.Text;
- using System.IO;
- namespace AX_Heuristic
- {
- class Program
- {
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- Application.Run(new Form1());
- }
- public job[] jobPool;
- public long[] schedule;
- public void AX1Program(string path)
- {
- List<string[]> jobData = new List<string[]>();
- Program agent = new Program();
- jobData = Program.parseCSV(path);
- agent.jobPool = new job[jobData.Count];
- int count = 0;
- long parent = 0;
- long jobId = 0;
- double dueDate = 0.00;
- foreach (string[] s in jobData)
- {
- //for (int i = 0; i < s.Length; i++)
- //{
- // //writes down the file values
- // Console.WriteLine(s[i]);
- //}
- //column 1 jobid
- //Column 2 bomid
- //column 3 parent
- //column 4 processign time
- //column 5 due date
- agent.jobPool[count] = new job(Convert.ToInt16(s[0]), Convert.ToInt64(s[1]), Convert.ToInt64(s[2]), Convert.ToDouble(s[3]), Convert.ToDouble(s[4]));
- parent = agent.jobPool[count].getParent();
- while (parent != 0)
- {
- dueDate = dueDate + methodpool.getJobbyJobId(agent.jobPool, parent).getProcessingTime();
- jobId = parent;
- parent = methodpool.getJobbyJobId(agent.jobPool, parent).getParent();
- }
- if (dueDate != 0)
- {
- agent.jobPool[count].setDuedate(methodpool.getJobbyJobId(agent.jobPool, jobId).getDueDate() - dueDate);
- }
- dueDate = 0;
- count++;
- }
- job tempJob = new job();
- bool swaped = true;
- int j = 0;
- // sort jobs by EDD
- while (swaped)
- {
- swaped = false;
- j++;
- for (int i = 0; i < count - j; i++)
- {
- if (agent.jobPool[i].getDueDate() > agent.jobPool[i + 1].getDueDate())
- {
- tempJob = agent.jobPool[i];
- agent.jobPool[i] = agent.jobPool[i + 1];
- agent.jobPool[i + 1] = tempJob;
- swaped = true;
- }
- }
- }
- // print sorted job
- Form1 Frm1 = new Form1();
- Frm1.UpdateStatusBar("Sorted jobs by EDD....");
- Frm1.Refresh();
- //Console.WriteLine("/n");
- foreach (job job in agent.jobPool)
- {
- Console.WriteLine("{0} {1} {2} {3} {4}", job.jobId.ToString(), job.bomId.ToString(), job.getParent(), job.getProcessingTime(), job.getDueDate());
- //Console.WriteLine("/n");
- }
- // make sched
- double totalCompletion = 0.00;
- bool end = false;
- int nextPos = 0;
- int nextpos1 = 0;
- long bomid;
- job highPi = new job();
- job job1 = new job();
- job dummy = new job();
- long[] schedule1 = new long[agent.jobPool.Length];
- agent.schedule = new long[agent.jobPool.Length];
- long[] earlyBom = new long[agent.jobPool.Length];
- long[] lateBom = new long[agent.jobPool.Length];
- Console.WriteLine("Start assigning jobs....");
- while (end == false)
- {
- foreach (job jb in agent.jobPool)
- {
- if (jb.flag == 0)
- {
- if (methodpool.isChildAssigned(agent.jobPool, jb.jobId) == false)
- {
- //assign job
- agent.schedule[nextPos] = jb.jobId;
- Console.WriteLine(jb.jobId);
- nextPos++;
- jb.flag = 1;
- // store total completion
- totalCompletion = totalCompletion + jb.getProcessingTime();
- //store highest pi job
- if (highPi.getProcessingTime() < jb.getProcessingTime())
- highPi = jb;
- // check Moore's modified criteria
- if (totalCompletion > jb.getDueDate())
- {
- Console.WriteLine("Late job...remove jobs...");
- //remove job from sched
- for (int m = 0; m < agent.schedule.Length; m++)
- {
- //no more iteration if last job of schedule is traversed
- if (agent.schedule[m] == 0)
- break;
- bomid = methodpool.getJobbyJobId(agent.jobPool, agent.schedule[m]).bomId;
- // get all jobs of same bom of highPi
- if (bomid == highPi.bomId)
- {
- // completion time reduction
- job1 = methodpool.getJobbyJobId(agent.jobPool, agent.schedule[m]);
- totalCompletion = totalCompletion - job1.getProcessingTime();
- // remove job at position m (shift later jobs from m left by one position)
- //for (int n = m; n < agent.schedule.Length - 1; n++)
- //{
- // agent.schedule[n] = agent.schedule[n + 1];
- // if (agent.schedule[n+1] == 0)
- // break;
- //}
- //nextPos--;
- Array.Clear(agent.schedule, m, 1);
- }
- }
- // flag all jobs in the jobpool
- foreach (job jb1 in agent.jobPool)
- {
- if (jb1.bomId == highPi.bomId)
- jb1.flag = 2;
- }
- nextPos = 0;
- highPi = dummy;
- Array.Clear(schedule1, 0, agent.schedule.Length);
- // get the new schedule after removing the cleared positions
- for (int m = 0; m < agent.schedule.Length; m++)
- {
- if (agent.schedule[m] != 0)
- {
- schedule1[nextPos] = agent.schedule[m];
- nextPos++;
- }
- }
- Array.Clear(agent.schedule, 0, agent.schedule.Length);
- agent.schedule = schedule1;
- // get new highPI
- highPi = dummy;
- for (int n = 0; n < agent.schedule.Length; n++)
- {
- job1 = methodpool.getJobbyJobId(agent.jobPool, agent.schedule[n]);
- if (agent.schedule[n] == 0)
- break;
- if (highPi.getProcessingTime() < job1.getProcessingTime())
- highPi = job1;
- }
- // write schedule after removal of job
- foreach (long jb2 in agent.schedule)
- {
- if (jb2 == 0)
- break;
- else
- Console.WriteLine(jb2);
- }
- Console.WriteLine("Start scheduling again");
- // remove all child
- //done above
- //flag off all jobs in the BOM
- //done above
- }
- }
- }
- }
- end = methodpool.isPoolEmpty(agent.jobPool);
- }
- // just assign the unassigned jobs according to precedence
- Console.WriteLine("Assign late jobs to the schedule");
- foreach (job jb2 in agent.jobPool)
- {
- if (jb2.flag == 2)
- {
- if (methodpool.isChildAssigned(agent.jobPool, jb2.jobId) == false)
- {
- //assign job
- agent.schedule[nextPos] = jb2.jobId;
- Console.WriteLine(jb2.jobId);
- nextPos++;
- //methodpool.getJobbyJobId(agent.jobPool, jb2.jobId).flag = 1;
- }
- }
- }
- Console.WriteLine("Final Schedule...");
- nextPos = 0;
- nextpos1 = 0;
- long bom = 0;
- foreach (long jb2 in agent.schedule)
- {
- Console.WriteLine(jb2);
- if (methodpool.getJobbyJobId(agent.jobPool, jb2).flag == 1)
- {
- bom = methodpool.getJobbyJobId(agent.jobPool, jb2).bomId;
- if (Array.Exists(earlyBom, element => element == bom) == false)
- {
- earlyBom[nextPos] = bom;
- nextPos++;
- }
- }
- else
- {
- bom = methodpool.getJobbyJobId(agent.jobPool, jb2).bomId;
- if (Array.Exists(lateBom, element => element == bom) == false)
- {
- lateBom[nextpos1] = bom;
- nextpos1++;
- }
- }
- }
- Console.WriteLine("Early BOMs...");
- foreach (long jb2 in earlyBom)
- {
- if (jb2 == 0)
- break;
- Console.WriteLine(jb2);
- }
- Console.WriteLine("Late BOMs...");
- foreach (long jb2 in lateBom)
- {
- if (jb2 == 0)
- break;
- Console.WriteLine(jb2);
- }
- Console.WriteLine("Press return to exit...");
- Console.ReadLine();
- }
- // function to read CSV file
- public static List<string[]> parseCSV(string path)
- {
- List<string[]> parsedData = new List<string[]>();
- try
- {
- using (StreamReader readFile = new StreamReader(path))
- {
- string line;
- string[] row;
- while ((line = readFile.ReadLine()) != null)
- {
- row = line.Split(',');
- parsedData.Add(row);
- }
- }
- }
- catch (Exception e)
- {
- MessageBox.Show(e.Message);
- }
- return parsedData;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement