我正在使用 c#; if
我通过以下语句处理该结果
:( EndTime = StartTime + Duration
)
// This is for handling start of M1J4 that starts after end of M2J2
// Bt I think this is out of 'Flow Shop Working'
if (i > 1)
if (M[m].jobs[i].StartTime < M[m + 1].jobs[i - 2].EndTime)
M[m].jobs[i].StartTime = M[m + 1].jobs[i - 2].EndTime;
if (i > 0)
if (M[m].jobs[i].StartTime < M[m + 1].jobs[i - 1].StartTime)
M[m].jobs[i].StartTime = M[m + 1].jobs[i - 1].StartTime;
if (M[m + 1].jobs[i].StartTime < M[m].jobs[i].EndTime)
M[m + 1].jobs[i].StartTime = M[m].jobs[i].EndTime;
我的控制台应用程序的代码是:
class job
{
public int Id { get; set; }
public int Duration { get; set; }
public int StartTime { get; set; }
public int EndTime { get { return this.StartTime + this.Duration; } }
public job(int _Id) { this.Id = _Id; }
public override string ToString()
{
if (this.Duration == 1)
return "|";
string result = "[";
for (int i = 0; i < this.Duration - 2; i++)
result += "#";
return result + "]";
}
}
class machine
{
public int Id { get; set; }
public List<job> jobs = new List<job>();
public int C_Max { get { return this.jobs[jobs.Count - 1].EndTime; } }
public machine(int _Id) { this.Id = _Id; }
public job AddJob(int _Duration)
{
int newId = 1;
if (newId < jobs.Count + 1)
newId = jobs.Count + 1;
jobs.Add(new job(newId));
jobs[newId - 1].Duration = _Duration;
if (newId == 1)
jobs[newId - 1].StartTime = 0;
else
jobs[newId - 1].StartTime = jobs[newId - 2].EndTime;
return jobs[newId - 1];
}
public void LagJobs(job fromJob, int lagDuration)
{
for (int i = fromJob.Id; i <= jobs.Count; i++)
jobs[i].StartTime += lagDuration;
}
public void AddJobs(int[] _Durations)
{
for (int i = 0; i < _Durations.Length; i++)
this.AddJob(_Durations[i]);
}
public override string ToString()
{
return this.ToString(false);
}
public string ToString(bool withMax)
{
string result = string.Empty;
for (int i = 0; i < jobs.Count; i++)
{
while (jobs[i].StartTime > result.Length)
result += " ";
result += jobs[i].ToString();
}
result = this.Id.ToString() + ". " + result;
if (withMax)
result += " : " + this.C_Max;
return result;
}
}
class Program
{
static void Main(string[] args)
{
int machinesCount = 4;
List<machine> machines = new List<machine>();
for (int i = 0; i < machinesCount; i++)
{
machines.Add(new machine(i + 1));
}
machines[0].AddJobs(new int[] { 5, 5, 3, 6, 3 });
machines[1].AddJobs(new int[] { 4, 4, 2, 4, 4 });
machines[2].AddJobs(new int[] { 4, 4, 3, 4, 1 });
machines[3].AddJobs(new int[] { 3, 6, 3, 2, 6 });
handelMachines(machines);
for (int i = 0; i < machinesCount; i++)
Console.WriteLine(machines[i].ToString(true));
Console.ReadKey();
}
static void handelMachines(List<machine> M)
{
if (M.Count == 2)
{
for (int i = 0; i < M[0].jobs.Count; i++)
{
if (i > 1)
if (M[0].jobs[i].StartTime < M[1].jobs[i - 2].EndTime)
M[0].jobs[i].StartTime = M[1].jobs[i - 2].EndTime;
if (i > 0)
if (M[0].jobs[i].StartTime < M[1].jobs[i - 1].StartTime)
M[0].jobs[i].StartTime = M[1].jobs[i - 1].StartTime;
if (M[1].jobs[i].StartTime < M[0].jobs[i].EndTime)
M[1].jobs[i].StartTime = M[0].jobs[i].EndTime;
}
}
else
{
for (int i = 0; i < M.Count - 1; i++)
{
List<machine> N = new List<machine>();
N.Add(M[i]);
N.Add(M[i + 1]);
handelMachines(N);
}
}
}
}
结果是: