lpsolve Question

Hi Guys,

I am using lpsolve to solve the following linear equation. I have my code working fine and I get the correct solution but now I am trying to solve the equation so that all my variables are constrained to be integers. I am quite lost as to how to do this. If you could help me that would be awesome. Here is the code that works but is not constrained to be integers as I am hoping for:

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

int main( int argc, char* argv[])
{
	lprec *lp;
	REAL solution[4];

	if ((lp = make_lp(0,4)) == NULL);

	{

		//first constraint		10*Ax + 12*Bx + 8*Cx + 18*Dx >= 55000
		//Second constrant		10*Ax + 12*Bx + 8*Cx + 18*Dx <= 65000
		{
			double row[] = {0,10,12,8,18};
			add_constraint(lp,row,GE,55000);
		}
		{
			double row[] = {0,10,12,8,18};
			add_constraint(lp,row,LE,65000);
		}


		//Thrid constraint		14*Ax + 11*Bx + 10*Cx + 17*Dx >= 60000
		//Fourth constraint		14*Ax + 11*Bx + 10*Cx + 17*Dx <= 69000
		{
			double row[] = {0,14,11,10,17};
			add_constraint(lp,row,GE,60000);
		}
		{
			double row[] = {0,14,11,10,17};
			add_constraint(lp,row,LE,69000);
		}


		//Fifth constraint		13*Ax + 10*Bx + 11*Cx + 20*Dx >= 62000
		//Sixth constraint		13*Ax + 10*Bx + 11*Cx + 20*Dx >= 68000
		{
			double row[] = {0,13,10,11,20};
			add_constraint(lp,row,GE,62000);
		}
		{
			double row[] = {0,13,10,11,20};
			add_constraint(lp,row,LE,68000);
		}

		
		//Seventh constraint	Ax >= 650
		//Eight constraint		AX <= 1000
		{
			double col[] = {0,1,0,0,0};
			add_constraint(lp,col,GE,650);
		}
		{
			double col[] = {0,1,0,0,0};
			add_constraint(lp,col,LE,1000);
		}


		//Ninth constraint		Bx >= 1700
		//Tenth constraint		Bx <= 2200
		{
			double col[] = {0,0,1,0,0};
			add_constraint(lp,col,GE,1700);
		}
		{
			double col[] = {0,0,1,0,0};
			add_constraint(lp,col,LE,2200);
		}


		//Eleventh constraint	Cx >= 1100
		//Twelfth constraint	Cx <= 1400
		{
			double col[] = {0,0,0,1,0};
			add_constraint(lp,col,GE,1100);
		}
		{
			double col[] = {0,0,0,1,0};
			add_constraint(lp,col,LE,1400);
		}


		//Thirteenth constraint	Dx >= 880
		//Fourteenth constraint	Dx >= 1300
		{
			double col[] = {0,0,0,0,1};
			add_constraint(lp,col,GE,880);
		}
		{
			double col[] = {0,0,0,0,1};
			add_constraint(lp,col,LE,1300);
		}


		// Maximize the Objective Function
		//Objective Function 4.5*Ax +5.5*Bx + 6.5*Cx + 7*Dx
		{
			double row[] = {0, -4.5, -5.5, -6.5, -7};
			set_obj_fn(lp,row);
		}

		solve(lp);

		cout << "Optimal Value is: " << -1*get_objective(lp) << endl;

		get_variables(lp, solution);
		cout << "Optimal solution: " << endl;
		for (int i=0; i < 4; i++)
				cout << "x[" << i+1 << "] = " << solution[i] << endl;

		delete_lp(lp);

		return(0);
	}
}
Last edited on
Anyone have any ideas?
Topic archived. No new replies allowed.