### Function problem when looping through

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475`` ``````#include #include using namespace std; void input(){ int numOfPerson = 0; int numOfJob = 0; cout << "Please enter number of person : "; cin >> numOfPerson; cout << "Please enter number of job : "; cin >> numOfJob; int **minimumCost; minimumCost = new int*[numOfPerson]; for( int i = 0 ; i < numOfJob ; i++ ){ minimumCost[i] = new int [numOfJob]; } /*cout << "\n\t\t" ; for( int i = 0 ; i < numOfJob; i++ ){ cout << "Job " << (i+1) << "\t"; }*/ cout << endl; for( int i = 0 ; i < numOfPerson ; i++ ){ cout << "\nEnter Person " << (i+1) << "\n--------------------------\n" ; for( int j = 0 ; j < numOfJob ; j++ ){ cout << "Cost for Job " << (j+1) << ":"; cin >> minimumCost[i][j]; } } cout << "\n\t\t" ; for( int i = 0 ; i < numOfJob; i++ ){ cout << "Job " << (i+1) << "\t"; } cout << endl; for( int i = 0 ; i < numOfPerson ; i++ ){ cout << "Person 1 \t "; for( int j = 0 ; j < numOfJob; j++ ){ cout << minimumCost[i][j] << "\t"; } cout << endl; } BranchandBound( minimumCost , numOfPerson , numOfJob ); } void BranchandBound( int **minimumCost , int p , int j ){ bool match = false; int a[p]; int totalCost = 0; for( int i = 0 ; i < p ; i++ ){ for( int temp = 0 ; temp < p ; temp++ ){ a[i] = minimumCost[i][j]; while( } } } int main(){ input(); system( "pause" ); return 0; } ``````

so far i did until this . just ask some login that can let me think through
for example now my minimum cost 2D array have
 ``1234`` ``````11 12 18 40 14 15 13 22 11 17 19 23 17 14 20 28``````

my question is i have two looping in my function `BranchandBond`
The first condition is i have to find the first column and which value is the smallest. and then when i chose that smallest value for the first column store into A.
i cannot choose any value that same row with it. so my looping will go for 2nd time. which is find the smallest value again , get the value then store to B. and then my looping will run again to get the value and store to C . and same process and save to D

for the first time i mentioned that first value mean choose, when other looping choose the smallest value, the value cannot be same row with the first input

so answer = A+B+C+D
main.cpp: In function 'void input()':
main.cpp:49: error: 'BranchandBound' was not declared in this scope
main.cpp: In function 'void BranchandBound(int**, int, int)':
main.cpp:63: error: expected primary-expression before '}' token
main.cpp:63: error: expected ')' before '}' token
main.cpp:63: error: expected primary-expression before '}' token
main.cpp:63: error: expected ';' before '}' token
main.cpp:54: warning: unused variable 'match'
main.cpp:57: warning: unused variable 'totalCost'
main.cpp: In function 'int main()':
main.cpp:71: error: 'system' was not declared in this scope
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 2 warnings

For the first error trying placing your void BranchandBound function above the place you call it.

For the main.cpp:63 error, you didn't finish your while statement.....while(

What is the purpose of bool match and int totalCost? You declare them but do not use them anywhere in the program?
of course my program a lot of error because i not yet done it.
i facing the problem at that function and i can't think any logic of it so only i post the question and stated clearly as above..
I think this problem is somewhat beyond beginners...
Plus I've never done anything with it.

When I understand this:

http://en.wikipedia.org/wiki/Branch_and_bound

right then you need to organize the data in a tree. The columns are the subset of the table and the rows are subsets of the columns. Normally you have an upper and a lower bound. But I think that you can do it with a lower bound only.

The trick would be that you eliminate anything that's greater than the lower bound for each column until only one element is left.

The result would be:
 `11 12 13 22`
(if I understand your requirement right?)
ya. i trying to use my own algorithm but failed.
you are correct. we doing branch and bound. we told our lecturer that previous assignment like AVL tree those thing we still able to do. but this is too hard.

for the first time . it should go to 11

when i choose the array [0][0] which is 11.

 ``12345`` ``````11 12 18 40 14 15 13 22 11 17 19 23 17 14 20 28 ``````

cannot be choose since it's same entire row and column. so i oni can choose those value that left at the table. get the minimum number for each COLUMN , not rows. for this table.
second column minimum number is 14 , third is 13 , fourth is 22 , so

the answer = 11 + 14 + 13 + 22 = 60

check this out yea. for me i think maybe not hard? is just the looping logic ?
http://faculty.cs.byu.edu/~ringger/Winter2006-CS312/lectures/lecture25-branchandbound.pdf
Last edited on
it's not just looping. See page 3 and the [implicit] tree structure.

to approach such a complex problem I recommend making small functions from what you currently know. Avoid deep nested loops.

What you currently know is that you need to find the minimum for a certain column. So I'd say that you implement this function that takes the table/column index and returns the minimum.

Then implement the first illustration: the 'criss cross' min/max
Then build the array of costs like on page 2.

 the answer = 11 + 14 + 13 + 22 = 60
yes, this is the value for the first column, repeat it for all column (into an array with the size of the columns).

if you accomplish that you'd a step closer.
Topic archived. No new replies allowed.