// // CSC 321, Assignment 4 test program alstest.cpp // // You may use this code to test your implementation of the algorithm // on p. 329 of the text. // // Read the description of the assembly-line scheduling problem and // solution on pp. 324-330 in the text. In that description, n is the // number of stations in the assembly lines. Also there, they // define the tables a, t, f, and l and the variables e1, e2, x1, and // x2. // The program assumes the data is coming from a text file called alsdata.txt, // which has the format: // // n // e1 e2 // a1,1 a2,1 t1,1 t2,1 // ... // a1,k a2,k t1,k, t2,k // ... // a1,n a2,n // x1 x2 // #include #include using namespace std; int main() { ifstream inputfile; inputfile.open("alsdata.txt"); // The four tables used are 2-by-n tables; that is, they each have two // rows and n columns. In C++, a two-dimensional table can be represented // as an array of pointers, where each pointer points to a row. int n; int **a; int **t; int **f; int **l; int e1, e2, x1, x2, fstar, lstar; // Read in the number of stations in the assembly lines. inputfile >> n; // Dynamically allocate space for each table. Even though a three element array // is allocated, we will only use entries 1 and 2 (i.e., we will not use // row 0). a = new int*[3]; a[1] = new int[n+1]; a[2] = new int[n+1]; t = new int*[3]; t[1] = new int[n+1]; t[2] = new int[n+1]; f = new int*[3]; f[1] = new int[n+1]; f[2] = new int[n+1]; l = new int*[3]; l[1] = new int[n+1]; l[2] = new int[n+1]; // Read all of the other data into the variables and tables. inputfile >> e1 >> e2; for (int i = 1; i < n; i++) { inputfile >> a[1][i] >> a[2][i] >> t[1][i] >> t[2][i]; } inputfile >> a[1][n] >> a[2][n]; inputfile >> x1 >> x2; // You will write this function. When it returns, the f and l tables // are filled in and fstar and lstar have received values. // // The function expects the variables n, e1, e2, x1, and x2 to have // values. It also expects the 2-by-n tables a and t to be filled // in with values. When it returns, it has filled in the 2-by-n tables // f and l and it has set fstar to be the minimal cost of a route and // lstar to the assembly line of the last station in the optimal // route. computeMinimumCost(n, e1, e2, a, t, x1, x2, f, l, fstar, lstar); cout << "Minimum cost is " << fstar << endl; printMinimumCostRoute(n, l, lstar); return 0; }