. , , ,

,,,

,



: ..

: ..


2002.

 

BORLAND ++ 3.1

 

() 3 :

1. -

2. -

3. .

:

1. Main()

2. Data()

3. Opplan()

4. Sohran()

5. Bas()

6. Kost()

7. Potenzial()

8. Optim()

9. Plmi()

10.  Abcikl()

11.  Cikl()

12.  Prpoisk()

13.  Levpoisk()

14.  Verpoisk()

15.  Nizpoisk()

16.  Pr()

main() , , . if(!z) break; - ( , , , optim() 0, ). , ( ) , . matr() 2. .

data() .

opplan() - . :

Int *matr

Int *po

Int *pn

Int m

Int n

kost() . :

Int *matr, m,n;

Int *st .

potenzial() .

:

Int *pu

Int *pv

Int matr, m, n, *st;

*(pu+i) *(pv+j) = 32768, define MIN 32768. , *pu=0, struct poten{}, .

:

     top = (struct poten*)malloc(sizeof(struct poten)); ; ;

     pu pv;

     pu pv, .. MIN. , , ;

     pu pv;

optim() , , main() 0, , , abcikl() main() 1. optim() :

Int m,n,*pu,*pv, *matr, *st. , ui + vj =cij , . , , , .

abcicl()

Int *matr, m, n;

Int *matr2 // () , .

Int ik,jk; // , . , (), -1.

cikl() 1. :

Int *matr2, ik, jk;

Int ch; // *zi *zj

Int *zi, *zj // . matr, .

prpoisk(), levpoisk(), verpoisk(), nizpoisk()-, , , , , . *matr2. , , .. , .

, 1, .

cikl() :

     , 1 matr2 ( ik jk ) ();

     , , ( , ), () matr2(). :

     - , ( ). matr2() , , , matr2, ;

     () , - matr2 1. , .. , zi zj.

:

Int m, n, *matr2;

:

Int i1, j1 // , .

:

I(j)- , , ;

pr(), ; cikl().

plmi() , .. .

:

Int zi,zj;

Int ch,chr; / zi,zj

Int matr /

. ( 2 matr) k zi,zj, matr, , 1 2( 2 ), , ( k matr) :

: min=matr [i][j], i=zi[k]; j=zj[k]; k- ;

:

a) k , matr[i][j] = matr[i][j]+min, i=zi[k]; j=zj[k];

b) k , matr[i][j] = matr[i][j]-min, i=zi[k]; j=zj[k];

bas() matr.

sohran() matr 2.

Int basper; / .

opplan1() - , opplan2()- .

#include <stdio.h> //

#include <alloc.h> //

#include <conio.h>

#include <process.h>

#include <stdlib.h>

#define MIN -32768

int *po = NULL; //

int *pn = NULL; //

int *st = NULL; //

int *matr=NULL; //

int *matr2 = NULL; //

int n ,m; //

int *pu,*pv; //

int *zj,*zi; //

int ch=0,ch2=0; //

FILE *fpdat; //

int iter=0; //

FILE *fil; //

int zen = -1; // -

int z = 1; //

int basper;

// void exit(int status);

void data(void)

{

int i,j,t;

printf(" : ");

scanf("%d",&m);

printf("Kolichestvo skladov-----> %d",m);

printf("\n :\n");

scanf("%d",&n);

printf("\n Kolichestvo magazinov --->%d",n);

//*********** ******************

if((po=(int*)calloc(m,sizeof(int)))==NULL) abort();

if((pn=(int*)calloc(n,sizeof(int)))==NULL) abort();

if((st=(int*)calloc(n*m,sizeof(int)))==NULL) abort();

printf(" : \n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

printf(" [%d][%d]\n ",i,j);

scanf("%d",&t);

*(st+i*n+j)=t;

}

}

printf("\n");

fprintf(fil,"\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

printf("%5d",*(st+i*n+j));

fprintf(fil,"%5d",*(st+i*n+j));

}

printf("\n");

fprintf(fil,"\n");

}

printf(" :\n");

for(i=0;i<m;i++)

{

printf("\n");

scanf("%d",po+i);

printf("%5d",*(po+i));

}

printf("\n");

printf(" :\n");

for(j=0;j<n;j++)

{

printf("\n");

scanf("%d",pn+j);

printf("%5d",*(pn+j));

}

return;

}//**** data

//************* SOZDANIE OPORNOGO PLANA ********************

//************* METHOD NORD-WEST YGLA **********************

void opplan(void)

{

int i,j,ch1 = 0;

//*************** *************************

if((matr=(int*)calloc(m*n,sizeof(int))) == NULL) abort();

//

for(i=0;i<m;i++)

{

for(j=ch1;j<n;j++)

{

if(*(po+i)<*(pn+j))

{

*(matr+i*n+j)=*(po+i);

*(pn+j)-=*(po+i);

*(po+i)=0;

break;

}

*(matr+i*n+j)=*(pn+j);

*(po+i) -= *(pn+j);

*(pn+j)=0;

ch1++;

}

}

//********* ***********************

printf("PROVERKA\n");

fprintf(fil,"PROVERKA MATRIX - ,\n \n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

printf("%5d",*(matr+i*n+j));

fprintf(fil,"%d",*(matr+i*n+j));

}

printf("\n");

fprintf(fil,"\n");

}

fprintf(fil,"********************\n");

return;

} // opplan

void kost(void)

{

int i,j, *matr1,rez=0;

//

if((matr1=(int*)calloc(n*m,sizeof(int))) == NULL) abort();

// ()

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

*(matr1+i*n+j) = *(matr+i*n+j);

}

}

// ( )

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

if(*(matr1+i*n+j)>0)

rez += (*(matr1+i*n+j)) *(*(st+i*n+j));

}

}

printf("\n Rezultat : %d",rez);

printf("\n");

fprintf(fil,"%s %5d"," Rezultat : ",rez);

fprintf(fil,"\n");

getch();

free(matr1);

if(zen == rez)

{

z=0;

}

zen = rez;

return;

}

//************* KOST()

//************* PODSCHET POTENCIALOV ********************

void potenzial(void)

{

struct poten

{

int v;

int u;

int zn;

struct poten *next;

int b;

} *topnast = NULL,

*top = NULL,

*top1 = NULL;

int i,j;

int fl;

//********** *******************8

if((pu=(int*)calloc(m,sizeof(int)))==NULL) abort();

if((pv=(int*)calloc(n,sizeof(int)))==NULL) abort();

// MIN

for(i=0;i<m;i++)

*(pu+i) = MIN;

for(j=0;j<n;j++)

*(pv+j) = MIN;

//

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

if((*(matr+i*n+j) > 0) || (*(matr+i*n+j)==-2))

{

if((top=(struct poten*)malloc(sizeof(struct poten)))==NULL)

abort();

fprintf(fil,"top = %d",top);

if(!topnast){

topnast = top;

fprintf(fil,"topnast = top = %d",top);

}

else top1 -> next=top;

top1=top;

top -> next=NULL;

top -> b = *(st+i*n+j); //

top -> v = j;

top -> u = i;

top -> zn = -1;

}

}

}

*pu = 0;

i=0; j = -1;

for(top = topnast;top!=NULL;top = top -> next)

{

if((top -> u) == i && (top -> v)!=j)

{

*(pv+(top -> v)) = (top -> b) - *(pu+i);

j = (top->v);

top -> zn = 0;

}

else{

for(top1 = topnast;top1 != NULL;top1 = top1->next)

{

if((top1->v) == j && (top1->u)!=i)

{

*(pu+(top1->u))=(top1->b) - *(pv+j);

i = (top1->u);

top1 ->zn = 0;

break;

}

}

}

}

// ********** *****************

for(;;){

fl = 0;

for(top = topnast;top!=NULL;top =top -> next)

{

if((top -> zn) == -1)

{

if(*(pu+(top ->u)) !=MIN)

{

*(pv+(top->v))=(top->b) - *(pu+(top ->u));

fl = 1;

top -> zn = 0;

}

if(*(pv+(top->v)) !=MIN)

{

*(pu+(top->u))=(top->b) - *(pv+(top->v));

fl=1;

top->zn = 0;

}

}

}

if(!fl) break;

}

printf("\n v:");

fprintf(fil,"\n **** v:");

for(i = 0;i<n;i++)

{

printf("%d",*(pv+i));

fprintf(fil,"%5d",*(pv+i));

}

getch();

printf("\n u: ");

fprintf(fil,"\n **** u: ");

for(i=0;i<m;i++)

{

printf("%d",*(pu+i));

fprintf(fil,"%5d",*(pu+i));

}

fprintf(fil,"\n");

for(top = topnast;top!=NULL;top = top->next)

free(top);

return;

} // potenzial

// ****** PROVERKA PLANA NA OPTIMALNOST' ************************

void abcikl(int ik,int jk);

int cikl(int ik,int jk);

void pr(char pr[],void *st); //

int prpoisk(int i1,int j1); //

int levpoisk(int i1,int j1); //

int verpoisk(int i1,int j1); //

int nizpoisk(int i1,int j1);

int optim(void)

{

int i,j;

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

//

//

// ik,jk -1

if(( *(pu+i)+ *(pv+j))>(*(st+i*n+j))&&((*(matr+i*n+j)) == 0))

{

abcikl(i,j);

fprintf(fil,"optim(): , main() -1,\n abcikl() i,j ");

return(-1);

}

}

}

fprintf(fil,"Plan optimalen");

return(0);

} // ******* optim() ***************

// ************** UPGRADE PLAN **************************

void abcikl(int ik,int jk)

{

int i,j;

fprintf(fil," abcikl()");

if((matr2=(int*)calloc(n*m,sizeof(int))) == NULL) abort();

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

*(matr2+i*n+j) = *(matr+i*n+j); //

}

}

*(matr2+ik*n+jk) = -1;

// ik,jk -1

printf("\n");

printf(" : \n\n");

fprintf(fil," : \n\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

fprintf(fil,"%5d",*(matr2+i*n+j));

printf("%5d",*(matr2+i*n+j));

}

fprintf(fil,"\n");

printf("\n");

}

fprintf(fil,"\n\n , , cikl(ik,jk) \n");

getch();

cikl(ik,jk);

return;

} // abcikl

// ********* FUNKCION POISKA CIKLA **************************

int cikl(int ik,int jk)

{

int nst,nstr,i,j,

perlev = 0,

perpr = 0;

int perver = 0,

perniz = 0,

fl = 0,

fl3 = 1;

int napr;

struct cik { int prnapr;

int ick;

int jck;

struct cik *next;

} *topnast1 = NULL,

*top2 = NULL,

*top3 = NULL;

ch = 0;

if((top2 = (struct cik*)malloc(sizeof(struct cik))) == NULL)

abort();

if(!topnast1)

{

topnast1=top2;

top3=top2;

top3->ick=ik;

top3->jck=jk;

}

else

top3->next=top2;

top3=top2;

top2->next=NULL;

top2->ick = ik;

top2->jck = jk;

ch++;

fprintf(fil,"\n\n while fl3 =%d \n",fl3);

pr("top2",top2);

fprintf(fil," , - \n :( \n");

printf(" , - \n :( \n");

printf("\n \t \t\tpress anykey to contunio\n");

getch();

while(fl3)

{

fl3=0;

fl = 0;

if((nst = prpoisk(ik,jk))>=0)

{

fprintf(fil,"\n\n!!!\n nst = %d \n",nst);

fprintf(fil," ...:Point found!\n");

printf(" RIGHT:Point found !\n\r");

napr = 2;

jk = nst;

top2->prnapr = 1;

}

else if((nstr = nizpoisk(ik,jk))>=0)

{

fprintf(fil,"DOWN: Point found !\n");

printf("DOWN: Point found !\n\r");

napr = 3;

ik = nstr;

top2->prnapr = 2;

}

else if((nst=levpoisk(ik,jk))>=0)

{

fprintf(fil,"LEFT:Point found !\n");

printf("LEFT:Point found !\n\r");

napr = 4;

jk = nst;

top2->prnapr = 3;

}

// **************** Prodolzhenie 1 poiska ***********************

else if((nstr = verpoisk(ik,jk))>=0)

{

fprintf(fil,"UP:Point found !\n");

printf("UP:Point found !\n\r");

napr = 1;

ik = nstr;

top2->prnapr = 4;

}

else

return(-1);

while(!fl || *(matr2+ik*n+jk)!=-1)

{

fl=1;

switch(napr)

{

case 1:

printf("Search to the right --->");

fprintf(fil,"Search to the right --->");

if((nst = prpoisk(ik,jk))>=0)

{

printf("founded\n\r");

fprintf(fil,"founded\n");

if((top2=(struct cik*)malloc(sizeof(struct cik)))==NULL)

abort();

if(!topnast1) topnast1=top2;

else top3 -> next=top2;

top3 = top2;

top2 -> next = NULL;

top2->ick = ik;

top2->jck = jk;

ch++;

top2->prnapr = 1;

pr("top2",top2);

napr = 2;

jk = nst;

perpr = perlev = 0;

} // **** IF *******

else

{

fprintf(fil,"Point not found ! Change direction to LEFT\n");

napr = 3;

perpr = 1;

}

break;

//***************** PRODOLZHENIE 2 POISKA ******************************

case 2:

printf("Search to the down --->");

fprintf(fil,"Search to the down --->");

if((nstr=nizpoisk(ik,jk))>=0)

{

if((top2=(struct cik*)malloc(sizeof(struct cik))) == NULL)

abort();

printf("founded\n\r"); fprintf(fil,"founded\n");

if(!topnast1) topnast1=top2;

else top3->next=top2;

top3=top2;

top2->next=NULL;

top2->ick = ik;

top2->jck = jk;

ch++;

top2->prnapr = 2;

pr("top2",top2);

napr = 3;

ik = nstr;

perniz=perver=0;

} //**** IF ********

else

{

fprintf(fil,"Point not found ! Change direction to UP\n");

napr = 4;

perniz = 1;

}

break;

case 3:

printf("Search to the left -->");

fprintf(fil,"Search to the left -->");

if((nst=levpoisk(ik,jk))>=0)

{

if((top2=(struct cik*)malloc(sizeof(struct cik))) == NULL)

abort();

printf("founded\n\r"); fprintf(fil,"founded\n");

if(!topnast1)

topnast1=top2;

else

top3->next=top2;

top3=top2;

top2->next=NULL;

top2->ick = ik;

top2->jck = jk;

ch++;

//************ PRODOLZHENIE 3 POISKA *************

top2->prnapr = 3;

pr("top2",top2);

napr = 4; jk = nst;

perlev = perpr = 0;

} // ******* IF *****

else{

fprintf(fil,"Point not found ! Change direction to RIGHT\n");

napr = 1;

perlev = 1;

}

break;

case 4:

printf("Search to the up --->");

fprintf(fil,"Search to the up --->");

if((nstr=verpoisk(ik,jk))>=0)

{

if((top2=(struct cik*)malloc(sizeof(struct cik)))==NULL)

abort();

printf("founded\n\r"); fprintf(fil,"founded\n");

if(!topnast1) topnast1=top2;

else top3->next=top2;

top3=top2;

top2->next=NULL;

top2->ick=ik;

top2->jck=jk;

ch++;

top2->prnapr = 4;

pr("top2",top2);

napr = 1;

ik = nstr;

perver = perniz = 0;

} // *****If **************

else

{

fprintf(fil,"Point not found ! Change direction to DOWN\n");

napr = 2;

perver = 1;

}

break;

} // ************ SWITCH ********************

// ************** PRODOLZHENIE 4 POISKA ********************

if(perlev == 1 && perpr == 1)

{

*(matr2+ik*n+jk) = 0;

ik = top3 ->ick;

jk = top3 ->jck;

napr = top3->prnapr;

top3 = topnast1;

printf("Zerro 1\n\r");

for(top2=topnast1;top2->next !=NULL;top2=top2->next)

top3 = top2;

top3 -> next=NULL;

perlev = perpr = 0; // if(ch == 1)

if(top2==top3)

{

fl3=1;

break;

}

else

{

top3->next=NULL;

free(top2);

ch--;

printf("Viynimaem tochky: (%d,%d)=%d\n",ik,jk,*(matr2+ik*n+jk));

fprintf(fil,"Viynimaem tochky: (%d,%d)=%d\n",ik,jk,*(matr2+ik*n+jk));

pr("top2",top2);

}

perpr = 0;

perlev = 0;

} // IF

if(perver == 1 && perniz == 1)

{

*(matr2+ik*n+jk)=0;

printf("Zerro 2\n\r");

ik=top3->ick;

jk = top3->jck;

napr = top3->prnapr;

top3 = topnast1;

for(top2 = topnast1;top2->next !=NULL;top2=top2->next)

top3 = top2; perver = perniz = 0;

if(top2==top3)

{

fl3=1;

break;

}

else

{

top3->next = NULL;

free(top2);

ch--;

// ******* PRODOLZHENIE 5 POISKA *********************

printf("Viynimaem tochky: (%d,%d) = %d\n",ik,jk,*(matr2+ik*n+jk));

fprintf(fil,"Viynimaem tochky: (%d,%d) = %d\n",ik,jk,*(matr2+ik*n+jk));

pr("top2",top2);

}

perver = 0;

perniz = 0;

} // IF

if(ch==0)

{

fl3=1;

break;

}

} //while

} //while

i=0;

if((zi = (int*)calloc(ch,sizeof(int))) == NULL ) abort();

if((zj = (int*)calloc(ch,sizeof(int))) == NULL ) abort();

printf("\n\r");

ch2 = ch;

for(top2 = topnast1;top2 !=NULL;top2 = top2->next)

{

*(zi+i) = top2 ->ick;

*(zj+i) = top2 ->jck;

i++;

}

return(0);

} // *********** cikl ****************************

int prpoisk(int i1, int j1)

{

int j;

for(j=j1+1;j<n;j++)

{

if((*(matr2+i1*n+j))!=0)

return(j);

}

return(-1);

}

int levpoisk(int i1,int j1)

{

int j;

for(j = j1-1;j>=0;j--)

{

if((*(matr2+i1*n+j))!=0)

return(j);

}

return(-1);

}

int verpoisk(int i1,int j1)

{

int i;

for(i=i1-1;i>=0;i--)

{

if((*(matr2+i*n+j1))!=0)

return(i);

}

return(-1);

}

int nizpoisk(int i1, int j1)

{

int i;

for(i = i1+1;i<m;i++)

{

if((*(matr2+i*n+j1))!=0)

return(i);

}

return(-1);

}

// ************* FUNCTION SEARCH ********************

void pr(char pr[],void *st)

{

struct cik { int prnapr;

int ick;

int jck;

struct cik *next;

} *ptr;

int i,j;

ptr = (struct cik *)st;

fprintf(fil,"Koordinatiy ytoplennoy tochki : %d and %d",ptr->ick,ptr->jck);

printf("Koordinatiy ytoplennoy tochki : %d and %d\n\r",ptr->ick,ptr->jck);

fprintf(fil,"and napravlenie");

printf("Napravlenie");

switch(ptr->prnapr)

{

case 1:

fprintf(fil,"Vpravo\n");

printf("Vpravo\n\r");

break;

case 2:

fprintf(fil,"Vniz\n");

printf("Vniz\n\r");

break;

case 3:

fprintf(fil,"Vlevo\n");

printf("Vlevo\n\r");

break;

case 4:

fprintf(fil,"Vverh\n");

printf("Vverh\n\r");

break;

default:

fprintf(fil,"Start\n");

printf("Start\n\r");

break;

}

fprintf(fil,"WORK MATRIX\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

fprintf(fil,"%5d",*(matr2+i*n+j));

}

fprintf(fil,"\n");

}

fprintf(fil,"************************************\n");

return;

}

// **************** UPGRADE PLAN *********************************//

void plmi(void)

{

int i,j,k,min,i1,j1,flagok;

ch = ch2;

flagok = 0;

i1=*zi;

j1 = *zj;

for(k=1;k<ch;k+=2){

i=*(zi+k);

j = *(zj+k);

if(*(matr+i*n+j) == -2){

*(matr+i1*n+j1) = *(matr+i*n+j);

*(matr+i*n+j) = 0;

flagok = 1;

break;

}

} // for

if(!flagok){

for(k=2;k<ch;k+=2){

i = *(zi+k);

j = *(zj+k);

if(*(matr+i*n+j) == -2)

*(matr+i*n+j) = 0;

} // for

i = *(zi+1);

j = *(zj+1);

min = *(matr+i*n+j);

for(k=3;k<ch;k+=2){

i=*(zi+k);

j=*(zj+k);

if(*(matr+i*n+j)<min)

min = *(matr+i*n+j);

}

if(min == -2) min = 0;

for(k=0;k<ch;k+=2){

i = *(zi+k);

j = *(zj+k);

*(matr+i*n+j) += min;

}

for(k=1;k<ch;k+=2){

i=*(zi+k);

j=*(zj+k);

*(matr+i*n+j)-=min;

}

} //if

// ***************** PROVERKA **************************//

printf("PROVERKA\n");

for(i=0;i<m;i++){

for(j=0;j<n;j++){

printf("%5d",*(matr+i*n+j));

}

printf("\n");

}

free(matr2);free(zi);free(zj);free(pu);free(pv);

return;

}

void Bas(void)

{

int i,j;

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

if(*(matr+i*n+j)!=0) basper++;

}

}

return;

}

void sohran(void)

{

// Sravnenie

int i,j,k;

for(k=0;k<ch;k++)

{

i=zi[k];

j=zj[k];

if((*(matr+i*n+j) == 0) && (basper < m+n-1))

{

*(matr+i*n+j) = -2;

basper++;

}//if

}

return;

}

// ************ SOZDANIE OPORNOGO PLANA **************************

// ************ METODOM SEVERNO-ZAPADNOGO YGLA *******************

void opplan1(void)

{

int i,j, ch1 = n-1;

//**************** Viydelenie pamyty *************************

if((matr=(int*)calloc(m*n,sizeof(int))) == NULL) abort();

for(i=0;i<m;i++)

{

for(j=ch1;j>=0;j--)

{

if(*(po+i)<*(pn+j))

{

*(matr+i*n+j)=*(po+i);

*(pn+j)-=*(po+i);

*(po+i)=0;

break;

}

*(matr+i*n+j)=*(pn+j);

*(po+i)-=*(pn+j);

*(pn+j)=0;

ch1--;

}

}

//*************** Proverka *************************

printf("Proverka\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

printf("%5d",*(matr+i*n+j));

}

printf("\n");

}

fprintf(fil,"matrix\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

fprintf(fil,"%5d",*(matr+i*n+j));

}

fprintf(fil,"\n");

}

fprintf(fil,"*****************\n");

return;

}//******** opplan1

//************** SOZDANIE OPORNOGO PLANA ********************

//*************** METHOD NORD-WEST YGOL *********************

void opplan2(void)

{

int i,j,k_i,k_j=0, min = 32767, *kontr,fl;

if((matr=(int*)calloc(m*n,sizeof(int))) == NULL) abort();

if((kontr=(int*)calloc(m*n,sizeof(int))) == NULL) abort();

for(i=0;i<m;i++){

for(j=0;j<n;j++){

*(kontr+i*n+j) = 0;

}

}

for(i=0;i<m;i++){

fl = 0;

while(!fl){

for(j=0;j<n;j++){

if(*(st+i*n+j)<min){

if(*(kontr+i*n+j) == 0) {

min = *(st+i*n+j);

k_i = i; k_j = j;

}

}

}

*(kontr+k_i*n+k_j) = 1;

if(*(po+k_i)<*(pn+k_j)) {

min = 32767;

*(matr+k_i*n+k_j)=*(po+k_i);

*(pn+k_j)=*(po+k_i);

*(po+k_i)=0;

break;

}

else {

*(matr+k_i*n+k_j)=*(pn+k_j);

*(po+k_i)-=*(pn+k_j);

*(pn+k_j)=0;

min = 32767;

if(*(po+k_i) == 0) fl = 1;

}

}

}

printf("Proverka\n"); // proverka

for(i=0;i<m;i++){

for(j=0;j<n;j++){

printf("%5d",*(matr+i*n+j));

}

printf("\n");

}

fprintf(fil," matr\n");

for(i=0;i<m;i++){

for(j=0;j<n;j++){

fprintf(fil,"%5d",*(matr+i*n+j));

}

fprintf(fil,"\n");

}

fprintf(fil,"*********************************\n");

return;

}// opplan2

void main()

{

int i,j,met;

int flagok;

fil = fopen("otchet.txt","w");

clrscr();

gotoxy(1,3);

printf("WARNING USERS ---->\n\n\n");

printf(" .\n\n");

printf(" , , -2;\n");

printf(", \n");

printf(" -1\n");

gotoxy(1,22);

printf("press anykey to contunio...\n");

getch();

clrscr();

data();

printf("press anykey to contunio...\n");

getch();

clrscr();

gotoxy(1,3);

printf("\n YOU selest method building first plan:\n");

printf("1-method NORD-WEST ygol\n");

printf("2-method NORD-EST ygol\n");

printf("3-method minimum element to string\n");

scanf("%d",&met);

gotoxy(1,22);

printf("press anykey, to contunie...\n");

getch();

//void opplan(void);

//void opplan1(void);

//void opplan2(void);

clrscr();

switch(met)

{

case 1: opplan();

break;

case 2: opplan1();

break;

case 3: opplan2();

break;

default: printf(" \n"); exit(-1);

}

basper = 0;

Bas();

flagok = 0;

if(basper<m+n-1)

{

//

//, , , M+N-1

while(!flagok)

{

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

if(*(matr+i*n+j)==0)

{

*(matr+i*n+j) = -2;

flagok = 1;

basper++;

break;

} //if

}

if(flagok) break;

}

if(basper<m+n-1) flagok = 0;

}//while

}//if

for(;;)

{

fprintf(fil,"*********** **********\n");

basper = 0;

Bas();

//void sohran(void);

if(iter>0)

{

// <m+n-1

if(basper <m+n-1) sohran();

}

kost(); //****** ******

potenzial(); //******* ********

ch2 = 0;

z = optim();

if(!z) break;

plmi();

iter++;

fprintf(fil,"%d ",iter);

}

//************* ************

printf("\n\nOPTIMAL PLAN :\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

printf("%5d",*(matr+i*n+j));

}

printf("\n");

}

fprintf(fil,"optimal PLAN :\n");

for(i=0;i<m;i++)

{

for(j=0;j<n;j++)

{

fprintf(fil,"%5d",*(matr+i*n+j));

}

fprintf(fil,"\n");

}

kost(); //************ ***********

fclose(fil);

clrscr();

printf(" otchet.txt");

getch();

return;

} // main

: .. : .. 2002.

 

 

 

! , , , .
. , :