Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.
#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <fstream>
using namespace std;
ofstream output_file; //declare file to output results to
void display_opening_logo(); //function declaration for the opening logo
void costMatrix(); //function declaration for cost matrix
void construct_V_prime_matrix();
void sorted_V_prime_matrix();
void construct_d_prime_matrix();
float f_star();
void calculateVmatrix(); //function declaration for the to-be calculated V matrix
const char SKIP = ' ';
int C_matrix[4][4] = { 0 };
int V_matrix[4][4] = { 0 };
int f_bar[1][1] = { 0 };
int V_prime_matrix[6][1] = { 0 };
int d_prime_matrix[1][6] = { 0 };
int d_matrix[4][4] = { { 0, 8, 10, 2 },
{ 8, 0, 4, 7 },
{ 10, 4, 0, 9 },
{ 2, 7, 9, 0 } };
int p_matrix[4][4] = { { 0, 4, 2, 3 },
{ 4, 0, 8, 27 },
{ 2, 8, 0, 30 },
{ 3, 27, 30, 0 } };
double b_matrix[4][4] = { { 0, 0.5, 4, 1 },
{ 0.5, 0, 0.5, 0.33333333333333333 },
{ 4, 0.5, 0, 0.1666666667 },
{ 1, 0.3333333333333333, 0.1666666667, 0 } };
int main()
{
int i, j, x, k;
display_opening_logo(); //function call for the opening logo
cout << setw(16) << SKIP << endl;
cout << "Press <Enter> to continue " << endl;
cout << setw(16) << SKIP << endl;
_getch();
cout << setw(65) << "This is the P matrix. It represents the number of trips " << endl;
cout << setw(50) << "between departmnts i and k." << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
cout << p_matrix[i][j] << " ";
cout << endl;
}
cout << setw(16) << SKIP << endl;
cout << "Press <Enter> to continue " << endl;
cout << setw(16) << SKIP << endl;
_getch();
cout << setw(16) << SKIP << endl;
cout << setw(65) << "This is the b matrix. It represents the cost of moving " << endl;
cout << setw(65) << "one unit of material between departments i and k through " << endl;
cout << setw(50) << "a distance of one unit" << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
cout << b_matrix[i][j] << " ";
cout << endl;
}
cout << setw(16) << SKIP << endl;
cout << "Press <Enter> to continue " << endl;
cout << setw(16) << SKIP << endl;
_getch();
cout << setw(16) << SKIP << endl;
cout << setw(65) << "This is the d matrix. It represents the distance " << endl;
cout << setw(50) << "between sites j and l." << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
cout << d_matrix[i][j] << " ";
cout << endl;
}
cout << setw(16) << SKIP << endl;
calculateVmatrix(); //function call for the calculated V matrix
costMatrix(); //function call for the cost matrix
float cost_of_original_layout = f_star();
cout << "Press <Enter> to continue " << endl;
cout << setw(16) << SKIP << endl;
char ch = _getch();
cout << "The cost of the original existing layout is " << "$" << fixed << showpoint << setprecision(2) << cost_of_original_layout << endl;
construct_V_prime_matrix();
sorted_V_prime_matrix();
for (int index = 0; index < 6; index++)
{
cout << V_prime_matrix[index] << " ";
cout << endl;
}
output_file.open("CN_JH_VM_EO_CS_ET.txt"); //opens file to recieve data
output_file << "************************************************************************** " << endl;
output_file << "*" << setw(33) << SKIP << "WELCOME" << setw(33) << "*" << endl;
output_file << "*" << setw(73) << "*" << endl;
output_file << "*" << setw(16) << SKIP << "To the Qudratic Assignment Problem Calculator" << setw(12) << "*" << endl;
output_file << "************************************************************************** " << endl;
output_file << setw(16) << SKIP << endl;
output_file << "*" << setw(16) << SKIP << "For IEGR 468: Advanced Material Handling Systems" << setw(9) << "*" << endl;
output_file << setw(16) << SKIP << endl;
output_file << setw(28) << SKIP << "By:Jeffrey Haley" << endl;
output_file << setw(28) << SKIP << " Vaughn Mason" << endl;
output_file << setw(28) << SKIP << " Carlos Neal" << endl;
output_file << setw(28) << SKIP << " Emmanuel Onafeko" << endl;
output_file << setw(28) << SKIP << " Christina Speaks" << endl;
output_file << setw(28) << SKIP << " Elvis Tangwan" << endl;
output_file << setw(16) << SKIP << endl;
output_file << "This calculator will find the minimum material handling cost required for " << endl;
output_file << setw(60) << "a layout given the initial deparments and sites." << endl;
output_file << "The cost of the original existing layout is " << "$" << fixed << showpoint << setprecision(2) << cost_of_original_layout << endl;
output_file << setw(65) << "This is the P matrix. It represents the number of trips " << endl;
output_file << setw(50) << "between departmnts i and k." << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
output_file << p_matrix[i][j] << " ";
output_file << endl;
}
output_file << setw(65) << "This is the b matrix. It represents the cost of moving " << endl;
output_file << setw(65) << "one unit of material between departments i and k through " << endl;
output_file << setw(50) << "a distance of one unit" << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
output_file << b_matrix[i][j] << " ";
output_file << endl;
}
output_file << setw(65) << "This is the d matrix. It represents the distance " << endl;
output_file << setw(50) << "between sites j and l." << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
output_file << d_matrix[i][j] << " ";
output_file << endl;
}
output_file << "The cost of the original existing layout is " << "$" << fixed << showpoint << setprecision(2) << cost_of_original_layout << endl;
output_file.close(); //closes file
system("PAUSE");
return 0;
}
void display_opening_logo() // function for the opening logo
{
cout << "************************************************************************** " << endl;
cout << "*" << setw(33) << SKIP << "WELCOME" << setw(33) << "*" << endl;
cout << "*" << setw(73) << "*" << endl;
cout << "*" << setw(16) << SKIP << "To the Qudratic Assignment Problem Calculator" << setw(12) << "*" << endl;
cout << "************************************************************************** " << endl;
cout << setw(16) << SKIP << endl;
cout << "*" << setw(16) << SKIP << "For IEGR 468: Advanced Material Handling Systems" << setw(9) << "*" << endl;
cout << setw(16) << SKIP << endl;
cout << setw(28) << SKIP << "By:Jeffrey Haley" << endl;
cout << setw(28) << SKIP << " Vaughn Mason" << endl;
cout << setw(28) << SKIP << " Carlos Neal" << endl;
cout << setw(28) << SKIP << " Emmanuel Onafeko" << endl;
cout << setw(28) << SKIP << " Christina Speaks" << endl;
cout << setw(28) << SKIP << " Elvis Tangwan" << endl;
cout << setw(16) << SKIP << endl;
cout << "This calculator will find the minimum material handling cost required for " << endl;
cout << setw(60) << "a layout given the initial deparments and sites." << endl;
}
void calculateVmatrix() // calculate the V matrix using the b and p matrices
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
V_matrix[i][j] = b_matrix[i][j] * p_matrix[i][j];
}
}
}
void costMatrix() //calculates the cost matrix from the V and d matrices
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
C_matrix[i][j] = V_matrix[i][j] * d_matrix[i][j];
}
}
}
float f_star() //calculates the f_star from the upper diagonal half of the cost matrix, and calls it the og_layout_cost
{
int og_layout_cost = 0;
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (i == j || j > i)
{
og_layout_cost += C_matrix[i][j];
}
}
}
return og_layout_cost;
}
void construct_V_prime_matrix() //calculates the f_star from the upper diagonal half of the cost matrix, and calls it the og_layout_cost
{
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (i < j || j > i)
{
V_prime_matrix[i][j] = V_matrix[i][j];
}
}
}
}
void sorted_V_prime_matrix()
{
for (int counter = 1; counter < 6; counter++)
{
for (int index = 0; index < 6; index++)
{
if (V_prime_matrix[index] > V_prime_matrix[index + 1])
{
int swapholder;
swapholder = V_prime_matrix[index];
V_prime_matrix[index] = V_prime_matrix[index + 1];
V_prime_matrix[index + 1] = swapholder;
}
}
}
}
void construct_d_prime_matrix() //calculates the f_star from the upper diagonal half of the cost matrix, and calls it the og_layout_cost
{
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (j > i)
{
d_prime_matrix[i][j] = d_matrix[i][j];
}
}
}
}
if (i < j || j > i)
int V_prime_matrix[6][1] = { 0 };
int d_prime_matrix[1][6] = { 0 };
void sorted_V_prime_matrix()
{
for (int counter = 1; counter < 6; counter++)
{
for (int index = 0; index < 6; index++)
{
if (V_prime_matrix[index] > V_prime_matrix[index + 1])
{
int swapholder;
swapholder = V_prime_matrix[index][0];
V_prime_matrix[index][0] = V_prime_matrix[index + 1][0];
V_prime_matrix[index + 1][0] = swapholder;
}
}
}
}
void construct_V_prime_matrix() //calculates the f_star from the upper diagonal half of the cost matrix, and calls it the og_layout_cost
{
int x=0;
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (i < j || j > i)
{
V_prime_matrix[x++][0] = V_matrix[i][j];
}
}
}
}
As you can see not, the 2nd dimension of the V_prime_matrix is not properly hardcoded to [0]. I then add an 'x' variable that will load the 6 indexes of V_prime_matrix properly.void sorted_V_prime_matrix()
{
for (int counter = 0; counter < 6; counter++)
{
for (int index = 0; index < 5; index++)
{
if (V_prime_matrix[index][0] > V_prime_matrix[index + 1][0])
{
int swapholder;
swapholder = V_prime_matrix[index][0];
V_prime_matrix[index][0] = V_prime_matrix[index + 1][0];
V_prime_matrix[index + 1][0] = swapholder;
}
}
}
}
construct_V_prime_matrix();
for (i = 0; i < 1; i++)
{
for (int j = 0; j < 6; j++)
cout << V_prime_matrix[i][j] << " ";
cout << endl;
}
V_prime_matrix[i][0]
This is because you declared the 2nd dimension to size 1.#include <iostream>
#include <stdio.h>
#include <iomanip>
#include <conio.h>
#include <fstream>
using namespace std;
ofstream output_file; //declare file to output results to
void display_opening_logo(); //function declaration for the opening logo
void costMatrix(); //function declaration for cost matrix
void construct_V_prime_matrix();
void sorted_V_prime_matrix();
void construct_d_prime_matrix();
float f_star();
void calculateVmatrix(); //function declaration for the to-be calculated V matrix
const char SKIP = ' ';
int C_matrix[4][4] = { 0 };
int V_matrix[4][4] = { 0 };
int f_bar[1][1] = { 0 };
int V_prime_matrix[1][6] = { 0 };
int d_prime_matrix[1][6] = { 0 };
int d_matrix[4][4] = { { 0, 8, 10, 2 },
{ 8, 0, 4, 7 },
{ 10, 4, 0, 9 },
{ 2, 7, 9, 0 } };
int p_matrix[4][4] = { { 0, 4, 2, 3 },
{ 4, 0, 8, 27 },
{ 2, 8, 0, 30 },
{ 3, 27, 30, 0 } };
double b_matrix[4][4] = { { 0, 0.5, 4, 1 },
{ 0.5, 0, 0.5, 0.33333333333333333 },
{ 4, 0.5, 0, 0.1666666667 },
{ 1, 0.3333333333333333, 0.1666666667, 0 } };
int main()
{
int i, j, x, k;
display_opening_logo(); //function call for the opening logo
cout << setw(16) << SKIP << endl;
cout << "Press <Enter> to continue " << endl;
cout << setw(16) << SKIP << endl;
_getch();
cout << setw(65) << "This is the P matrix. It represents the number of trips " << endl;
cout << setw(50) << "between departmnts i and k." << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
cout << p_matrix[i][j] << " ";
cout << endl;
}
cout << setw(16) << SKIP << endl;
cout << "Press <Enter> to continue " << endl;
cout << setw(16) << SKIP << endl;
_getch();
cout << setw(16) << SKIP << endl;
cout << setw(65) << "This is the b matrix. It represents the cost of moving " << endl;
cout << setw(65) << "one unit of material between departments i and k through " << endl;
cout << setw(50) << "a distance of one unit" << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
cout << b_matrix[i][j] << " ";
cout << endl;
}
cout << setw(16) << SKIP << endl;
cout << "Press <Enter> to continue " << endl;
cout << setw(16) << SKIP << endl;
_getch();
cout << setw(16) << SKIP << endl;
cout << setw(65) << "This is the d matrix. It represents the distance " << endl;
cout << setw(50) << "between sites j and l." << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
cout << d_matrix[i][j] << " ";
cout << endl;
}
cout << setw(16) << SKIP << endl;
calculateVmatrix(); //function call for the calculated V matrix
costMatrix(); //function call for the cost matrix
float cost_of_original_layout = f_star();
cout << "Press <Enter> to continue " << endl;
cout << setw(16) << SKIP << endl;
char ch = _getch();
cout << "The cost of the original existing layout is " << "$" << fixed << showpoint << setprecision(2) << cost_of_original_layout << endl;
construct_V_prime_matrix();
for (i = 0; i < 6; i++)
{
for (int j = 0; j < 1; j++)
cout << V_prime_matrix[i][0] << " ";
cout << endl;
}
output_file.open("CN_JH_VM_EO_CS_ET.txt"); //opens file to recieve data
output_file << "************************************************************************** " << endl;
output_file << "*" << setw(33) << SKIP << "WELCOME" << setw(33) << "*" << endl;
output_file << "*" << setw(73) << "*" << endl;
output_file << "*" << setw(16) << SKIP << "To the Qudratic Assignment Problem Calculator" << setw(12) << "*" << endl;
output_file << "************************************************************************** " << endl;
output_file << setw(16) << SKIP << endl;
output_file << "*" << setw(16) << SKIP << "For IEGR 468: Advanced Material Handling Systems" << setw(9) << "*" << endl;
output_file << setw(16) << SKIP << endl;
output_file << setw(28) << SKIP << "By:Jeffrey Haley" << endl;
output_file << setw(28) << SKIP << " Vaughn Mason" << endl;
output_file << setw(28) << SKIP << " Carlos Neal" << endl;
output_file << setw(28) << SKIP << " Emmanuel Onafeko" << endl;
output_file << setw(28) << SKIP << " Christina Speaks" << endl;
output_file << setw(28) << SKIP << " Elvis Tangwan" << endl;
output_file << setw(16) << SKIP << endl;
output_file << "This calculator will find the minimum material handling cost required for " << endl;
output_file << setw(60) << "a layout given the initial deparments and sites." << endl;
output_file << "The cost of the original existing layout is " << "$" << fixed << showpoint << setprecision(2) << cost_of_original_layout << endl;
output_file << setw(65) << "This is the P matrix. It represents the number of trips " << endl;
output_file << setw(50) << "between departmnts i and k." << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
output_file << p_matrix[i][j] << " ";
output_file << endl;
}
output_file << setw(65) << "This is the b matrix. It represents the cost of moving " << endl;
output_file << setw(65) << "one unit of material between departments i and k through " << endl;
output_file << setw(50) << "a distance of one unit" << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
output_file << b_matrix[i][j] << " ";
output_file << endl;
}
output_file << setw(65) << "This is the d matrix. It represents the distance " << endl;
output_file << setw(50) << "between sites j and l." << endl;
for (i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
output_file << d_matrix[i][j] << " ";
output_file << endl;
}
output_file << "The cost of the original existing layout is " << "$" << fixed << showpoint << setprecision(2) << cost_of_original_layout << endl;
output_file.close(); //closes file
system("PAUSE");
return 0;
}
void display_opening_logo() // function for the opening logo
{
cout << "************************************************************************** " << endl;
cout << "*" << setw(33) << SKIP << "WELCOME" << setw(33) << "*" << endl;
cout << "*" << setw(73) << "*" << endl;
cout << "*" << setw(16) << SKIP << "To the Qudratic Assignment Problem Calculator" << setw(12) << "*" << endl;
cout << "************************************************************************** " << endl;
cout << setw(16) << SKIP << endl;
cout << "*" << setw(16) << SKIP << "For IEGR 468: Advanced Material Handling Systems" << setw(9) << "*" << endl;
cout << setw(16) << SKIP << endl;
cout << setw(28) << SKIP << "By:Jeffrey Haley" << endl;
cout << setw(28) << SKIP << " Vaughn Mason" << endl;
cout << setw(28) << SKIP << " Carlos Neal" << endl;
cout << setw(28) << SKIP << " Emmanuel Onafeko" << endl;
cout << setw(28) << SKIP << " Christina Speaks" << endl;
cout << setw(28) << SKIP << " Elvis Tangwan" << endl;
cout << setw(16) << SKIP << endl;
cout << "This calculator will find the minimum material handling cost required for " << endl;
cout << setw(60) << "a layout given the initial deparments and sites." << endl;
}
void calculateVmatrix() // calculate the V matrix using the b and p matrices
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
V_matrix[i][j] = b_matrix[i][j] * p_matrix[i][j];
}
}
}
void costMatrix() //calculates the cost matrix from the V and d matrices
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
C_matrix[i][j] = V_matrix[i][j] * d_matrix[i][j];
}
}
}
float f_star() //calculates the f_star from the upper diagonal half of the cost matrix, and calls it the og_layout_cost
{
int og_layout_cost = 0;
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (i == j || j > i)
{
og_layout_cost += C_matrix[i][j];
}
}
}
return og_layout_cost;
}
void sorted_V_prime_matrix()
{
for (int counter = 0; counter < 6; counter++)
{
for (int index = 0; index < 5; index++)
{
if (V_prime_matrix[index][0] > V_prime_matrix[index + 1][0])
{
int swapholder;
swapholder = V_prime_matrix[index][0];
V_prime_matrix[index][0] = V_prime_matrix[index + 1][0];
V_prime_matrix[index + 1][0] = swapholder;
}
}
}
}
void construct_V_prime_matrix() //calculates the f_star from the upper diagonal half of the cost matrix, and calls it the og_layout_cost
{
int x = 0;
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (i < j || j > i)
{
V_prime_matrix[x++][0] = V_matrix[i][j];
}
}
}
}
void construct_d_prime_matrix() //calculates the f_star from the upper diagonal half of the cost matrix, and calls it the og_layout_cost
{
for (int i = 0; i<4; i++)
{
for (int j = 0; j<4; j++)
{
if (j > i)
{
d_prime_matrix[i][j] = d_matrix[i][j];
}
}
}
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
c++ how to tell if the progra is ctl or mfc atl ect | 6 | 76 | |
Slower App speed with Visual Studio 2013 compilation when compared to VS2008 compilation? | 5 | 106 | |
C language IDE â€“ Compilers installation | 14 | 71 | |
PDF library for Delphi | 2 | 120 |
Join the community of 500,000 technology professionals and ask your questions.