Single shape solves line planning problems (c)

zhaozj2021-02-16  54

Single shape solves line planning problems (c)

The final is completed, the following is the code. Also: Because of the operation of the training, this time, a classmate, a classmate, a simple code, so there is this. I started reading this book yesterday. If there is a mistake, please forgive me ------ I feel that the operational training is really not easy, although I can't get our discrete:) ~~~~~~~~

Test Results: Successful: X [3] = 77.142860 x [1] = 7.142854 x [2] = 28.571430max z = 585.714294press any key to Continue

/**data.txt*//

5 2 1 0 02 3 0 1 01 5 0 0 1

170 100 150

10 18 0 0 0

1 0 00 1 00 0 1

1 0 00 1 00 0 1

0 0 0

2 3 4

/ * The example of this question is:

Max z = 10 * x1 18 * x2; s.t. 5 * x1 2 * x2 <= 1702 * x1 3 * x2 <= 100x1 5 * x2 <= 150x1, x2> = 0

The data of this document is data in the form of the above equation after the relax variable.

* /

/ **fmain.cpp*/#include #include #define m 3 # define n 5

/ * Line-shaped planning problem such as Max Z = cxs.t. AX = B, X> = 0

_B [M] [M] is B [M] [M] inverse array * / float a [m] [n], b [m], c [n], b [m] [m], cn [m ], X [M], Y [M], KAO [N], P [M], E [M] [M], _ B [M] [M]; / * Decoction No. * / INT Xcount [M]; Float Sita; / * Obedom Variable, Outbound Variable * / INT xin, Xout

Int init (file * pf); void compute_b (); void computexy (); int computekao (); int computepsita (); void computebcn (); int succ (); int fall ();

Void main () {file * pf; float result = 0.0; if (! init) {printf ("Error: can't open data file, please check ... / n"); exit (-1) Computexy (); xin = computekao (); while (! Succ ()) {xout = computepsita (); if (fall ()) {Printf ("Fall ... already exit ... / n"); EXIT (0);} computebcn (); computeE (); computexy (); xin = computekao ();} printf ("sucssful: / n"); for (int i = 0; i

For (int i = 0; i

/ * INPUT C [N] * / for (int i = 0; i

/ * INPUT B [M] [M] * / for (INT i = 0; I

/ * Input _b [m] [m] * / for (int i = 0; i

/ * INPUT CN [M] * / for (int i = 0; i

/ * Input xcount [m] * / for (int i = 0; i

/ * Other * / for (int i = 0; i

For (int i = 0; i

Fclose (PF); RETURN 1;} / * calculates the primary transformation matrix E * / void compute () {for (int i = 0; i

For (int i = 0; i

For (int i = 0; i

}

/ * Calculate x = _b * b, y = _b * cn * / void computexy () {for (int i = 0; i

For (int i = 0; i

} / * Calculation test number kaO = c-cn * _b * a xin <-return * / int computekao () {float midval = 0.0; int K; for (int i = 0; i midval) {midval = kao [j]; k = j;}

RETURN K;} / * Calculate the base variable vector p, determine the base variable Xout <-RETURN * / INT computepsita () {INT K = 0; for (int i = 0; i

SITA = X [0] / P [0]; for (int J = 0; j X [J] / P [J]) {sita = x [j] / p [j ]; K = j;}

Return K;} / * calculation matrix B, cn * / void computebcn () {for (int i = 0; i

Xcount [xout] = xin;} / * Judgment is successful * / int SUCC () {INT K = 1; for (int i = 0; i

Return K;} / * algorithm failed, exit * / int fall () {INT K = 1; for (int i = 0; i

转载请注明原文地址:https://www.9cbs.com/read-25448.html

New Post(0)