Problem description:
It is the fastest way to identify manufacturing problems through factory assembly lines. There are two assembly lines. Each assembly line has n assembly stations numbered j = 0, 1 ,... , N-1. Assembly line I (I = 0 or 1), the Assembly time required on the assembly station S [I] [j] is recorded as a [I] [j]. A car chassis enters the factory, and then enters the assembly line I at e [I]. After passing through the j assembly station of a line, this chassis comes to the assembly station (j + 1) of any line. If it remains on the same assembly line, there is no moving overhead; if it is moved to another line after the assembly station S [I] [j, it takes t [I] [j]. After leaving the nth assembly station of a line, the departure time for the finished car to exit assembly line I is x [I].
State transition equation:
Code implementation:
[Cpp]
// Dynamic planning, factory assembly line
# Include <iostream>
Using namespace std;
// E1, e2 is the input cost of the two assembly production lines x1, x2 is the output cost, a1 [I] is the time consumption of the first production line station I, t1, t2 records the time consumed for switching two production lines
// F1 [I] records the least time consumed by the first station in the first production line. L1 [I] records the minimum time consumed by the first station in the first production line, the previous station was on that production line.
// Length indicates the number of stations on each production line.
Void FastWay (int e1, int e2, int * a1, int * a2, int x1, int x2, int * f1, int * f2, int * L1, int * L2, int & L, int * t1, int * t2, int length)
{
F1 [1] = e1 + a1 [1];
F2 [1] = e2 + a2 [1];
Int I;
For (I = 2; I <length; I ++)
{
If (f1 [I-1] + a1 [I] <f2 [I-1] + a1 [I] + t2 [I-1])
{
F1 [I] = f1 [I-1] + a1 [I];
L1 [I] = 1;
}
Else
{
F1 [I] = f2 [I-1] + a1 [I] + t2 [I-1];
L1 [I] = 2;
}
If (f2 [I-1] + a2 [I] <f1 [I-1] + a2 [I] + t1 [I-1])
{
F2 [I] = f2 [I-1] + a2 [I];
L2 [I] = 2;
}
Else
{
F2 [I] = f1 [I-1] + a2 [I] + t1[ I-1];
L2 [I] = 1;
}
}
// Use f1 [length] to store the minimum time used
If (f1 [length-1] + x1 <f2 [length-1] + x2)
{
F1 [length] = f1 [length-1] + x1;
L = 1;
}
Else
{
F1 [length] = f2 [length-1] + x2;
L = 2;
}
}
// Output the shortest time and required route
Void Printanswser (int * L1, int * L2, int L, int length, int * f1)
{
Int I = L;
Cout <"the fast time is:" <f1 [length + 1] <endl;
Cout <"the station:" <length <"is on line:" <I <endl;
Int j;
For (j = length; j> = 2; j --)
{
If (I = 1)
{
I = L1 [j];
}
Else
{
I = L2 [j];
}
Cout <"the station:" <J-1 <"is on line:" <I <endl;
}
}
Int main ()
{
Int e1 = 2, e2 = 4, x1 = 3, x2 = 2;
Int a1 [8] = {, 9, 3, 4 };
Int a2 [8] = {, 6, 7 };
Int t1 [6] = {0, 2, 3, 1, 3, 4 };
Int t2 [6] = {0, 2, 2, 2, 1 };
Int f1 [8], f2 [7], L1 [7], L2 [7], L;
FastWay (e1, e2, a1, a2, x1, x2, f1, f2, L1, L2, L, t1, t2, 7 );
Printanswser (L1, L2, L, 6, f1 );
Return 0;
}
// Dynamic planning, factory assembly line
# Include <iostream>
Using namespace std;
// E1, e2 is the input cost of the two assembly production lines x1, x2 is the output cost, a1 [I] is the time consumption of the first production line station I, t1, t2 records the time consumed for switching two production lines
// F1 [I] records the least time consumed by the first station in the first production line. L1 [I] records the minimum time consumed by the first station in the first production line, the previous station was on that production line.
// Length indicates the number of stations on each production line.
Void FastWay (int e1, int e2, int * a1, int * a2, int x1, int x2, int * f1, int * f2, int * L1, int * L2, int & L, int * t1, int * t2, int length)
{
F1 [1] = e1 + a1 [1];
F2 [1] = e2 + a2 [1];
Int I;
For (I = 2; I <length; I ++)
{
If (f1 [I-1] + a1 [I] <f2 [I-1] + a1 [I] + t2 [I-1])
{
F1 [I] = f1 [I-1] + a1 [I];
L1 [I] = 1;
}
Else
{
F1 [I] = f2 [I-1] + a1 [I] + t2 [I-1];
L1 [I] = 2;
}
If (f2 [I-1] + a2 [I] <f1 [I-1] + a2 [I] + t1 [I-1])
{
F2 [I] = f2 [I-1] + a2 [I];
L2 [I] = 2;
}
Else
{
F2 [I] = f1 [I-1] + a2 [I] + t1[ I-1];
L2 [I] = 1;
}
}
// Use f1 [length] to store the minimum time used
If (f1 [length-1] + x1 <f2 [length-1] + x2)
{
F1 [length] = f1 [length-1] + x1;
L = 1;
}
Else
{
F1 [length] = f2 [length-1] + x2;
L = 2;
}
}
// Output the shortest time and required route
Void Printanswser (int * L1, int * L2, int L, int length, int * f1)
{
Int I = L;
Cout <"the fast time is:" <f1 [length + 1] <endl;
Cout <"the station:" <length <"is on line:" <I <endl;
Int j;
For (j = length; j> = 2; j --)
{
If (I = 1)
{
I = L1 [j];
}
Else
{
I = L2 [j];
}
Cout <"the station:" <J-1 <"is on line:" <I <endl;
}
}
Int main ()
{
Int e1 = 2, e2 = 4, x1 = 3, x2 = 2;
Int a1 [8] = {, 9, 3, 4 };
Int a2 [8] = {, 6, 7 };
Int t1 [6] = {0, 2, 3, 1, 3, 4 };
Int t2 [6] = {0, 2, 2, 2, 1 };
Int f1 [8], f2 [7], L1 [7], L2 [7], L;
FastWay (e1, e2, a1, a2, x1, x2, f1, f2, L1, L2, L, t1, t2, 7 );
Printanswser (L1, L2, L, 6, f1 );
Return 0;
}
Running result: