Function problem when looping through

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include <string>

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
1
2
3
4
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.

1
2
3
4
5
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.