Simple Form Method for Optimal Solution

Source: Internet
Author: User

Debugging is successful, and a running error occurs!

Hope to find out the problem and give a reply:

The source program is as follows:

# Include <stdio. h>
# Include <math. h>

Int M, N, P, T, S;

Print (int A [] [10]);

Main ()
{
Int A [10] [10]; // 001
Int L [10];
Int X [10];
Int I, j, A, B, C;
Int D, E, Y;
Double E;
Printf ("m = ");
Scanf ("% d", & );
Printf ("n = ");
Scanf ("% d", & B );
Printf ("P = ");
Scanf ("% d", & C );
M =;
N = B;
P = C;

Printf ("input matrix A/N ");
For (I = 2; I <= m + 1; I ++ ){
For (j = 1; j <= n + 2; j ++ ){
Printf ("A [% d] [% d] =", I, j );
Scanf ("% d", & D );
A [I] [J] = D;
}
}
Print ();

For (I = 2; j <= m + 1; I ++ ){
For (j = 1; j <= n + 2; j ++ ){
If (A [I] [n + 2]> 0)
A [I] [J] = A [I] [J];
If (A [I] [n + 2] <0)
A [I] [J] =-A [I] [J];
Else
A [I] [J] = 0;
}
}
Printf ("/ninput objective function/N ");
For (I = 1; I <= N; I ++ ){
Printf ("A [1] [% d] =", I );
Scanf ("% d", & E );
A [1] [I] = E;
}
Printf ("/n/tobjective function/N ");
For (I = 1; I <= N; I ++ ){
Printf ("/T % d/T", a [1] [I]);
}
Printf ("/n ===============================/N ");

E = 0.0001; // line54
For (I = 1; I <= N; I ++ ){
A [1] [I] =-p * A [1] [I];
}
 
If (M = 1) {// line62
Int r = 1;
For (I = 2; I <= m + 1; I ++ ){
L [I] = N + I-1;
If (A [I] [n + I-1] = 1 ){
Continue;
}
L [I] = m + n + 1;
For (j = 1; j <= m + n; j ++ ){
A [M + 2] [J] = A [M + 2] [J]-A [I] [J];
}
R = m + 2;
}
Label: T = 1; // 98
For (I = 2; I <= m + n; I ++) {// line100
If (A [r] [I]-A [r] [T])> E)
Continue;
If (A [r] [I]-A [r] [T]) <-e ){
T = I;
Continue;
}
If (r = 1 ){
Continue;
}
If (A [1] [I]-A [1] [T])>-E)
Continue;
}
If (A [r] [T] <-e) {// line114
S = 1;
For (I = 2; I <= m + 1; I ++ ){
If (A [I] [T] <= E)
Continue;
Y = a [I] [M + n + 1]/A [I] [T];
If (S = 1 ){
S = I;
Continue;
}
If (Y> = A [s] [M + n + 1]/A [s] [T])
Continue;
}
If (S = 1) {// 154
Printf ("unbounded ");
Printf ("=================="); // 214
Exit (1 );
}
L [s] = T; // 156
Y = a [s] [T];
For (I = 1; I <= m + n + 1; I ++ ){
A [s] [I] = A [s] [I]/y;
}
For (I = 1; I <= m + 2; I ++ ){
If (I = s) // 168
Continue;
Y = a [I] [T];
For (j = 1; j <= m + n + 1; j ++ ){
A [I] [J] = A [I] [J]-y * A [s] [J];
}
}
Goto label; // 180
Printf ("infeaslble ");
Printf ("=================="); // 214
Exit (1 );
}
If (r = 1) {// 116
For (I = 2; I <= m + 1; I ++) {// 190
If (L [I]> N)
Continue;
S = L [I];
X [s] = A [I] [M + n + 1];
}
Y = p * A [I] [M + n + 1];
Printf ("obj. func. z = % F/N", y );
Printf ("optimal solution x [I]:/N ");
For (I = 1; I <= N; I ++ ){
Printf ("X [% d] = % d/T", X [I]);
}
Printf ("========================= ");
Exit (1 );
}
For (I = 1; I <= m + n; I ++) {// 118
If (A [r] [I]> E) {// 120
For (I = 2; I <m + 1; I ++) {// 128
If (L [I] <= (m + n ))
Continue;
If (A [I] [M + n + 1]> E) {// 132
Printf ("infeaslble"); // 182
Printf ("=================="); // 214
Exit (1 );
}
}
R = 1;
Goto label; // 126
}
}
For (I = 2; I <= m + 1; I ++) {// 190
If (L [I]> N)
Continue;
S = L [I];
X [s] = A [I] [M + n + 1];
}
Y = p * A [I] [M + n + 1];
Printf ("obj. func. z = % d/N", y );
Printf ("optimal solution x [I]:/N ");
For (I = 1; I <= N; I ++ ){
Printf ("X [% d] = % d/T", X [I]);
}
Printf ("========================= ");
Exit (1 );
} // End of commence 62

For (I = 2; I <= m + n + 1; I ++) {// 64
A [I] [M + n + 1] = A [I] [n + 2];
A [I] [n + 1] = 0;
If (I = 1)
Continue;
A [I] [n + I-1] = A [I] [n + 1];
A [I] [n + 1] = 0;
}
}

/X 888888888888888888888888888888888888888888888888888 */
Print (int A [] [10]) {
Int I, J;
Printf ("/n/tnow the matrix A is:/N ");
For (I = 2; I <= m + 1; I ++ ){
Printf ("/N ");
For (j = 1; j <= n + 2; j ++ ){
Printf ("% 6D/T", a [I] [J]);
}
}
Printf ("/N ");
Getch ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.