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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
//calcul du minorant de M
public int calculMinorant(int M[][])
{
int M2[][]=M;
int Min=0;
for(int i=0; i<M.length; i++)
{
Min+=minRow(i, M);
updateRow(minRow(i, M), i, M2);
}
for(int j=0; j<M.length; j++)
{
Min+=minCol(j, M2);
}
return Min;
}
//le min de la ligne:
public int minRow(int l, int M[][])
{
int n=M.length;
int mr=1000000;
for(int j=0; j<n; j++)
{
if((M[l][j]<mr)&&(M[l][j]!=-1))
mr=M[l][j];
}
if(mr==1000000)
mr=0;
return mr;
}
//m-a-j de la ligne:
public void updateRow(int r, int l, int M[][])
{
int n=M.length;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
{
if(i==l)
if(M[i][j]!=-1)
M[i][j]=M[i][j]-r;
}
}
//min de la colonne:
public int minCol(int c, int M[][])
{
int n=M.length;
int mc=1000000;
for(int i=0; i<n; i++)
{
if((M[i][c]<mc)&&(M[i][c]!=-1))
mc=M[i][c];
}
if(mc==1000000)
mc=0;
return mc;
}
//réduire M en enlevant les mins des lignes puis des cols
//pour avoir des 0 ds chaque ligne et chaque colonne:
public int[][] updateMat(int M[][])
{
int M2[][]=new int[M.length][M.length];
for(int i=0; i<M.length; i++)
for(int j=0; j<M.length; j++)
{
if(M[i][j]==-1)
M2[i][j]=M[i][j];
if(M[i][j]!=-1)
M2[i][j]=M[i][j]-minRow(i, M);
}
int M3[][]=new int[M.length][M.length];
for(int k=0; k<M.length; k++)
for(int l=0; l<M.length; l++)
{
if(M2[l][k]==-1)
M3[l][k]=M2[l][k];
if(M2[l][k]!=-1)
M3[l][k]=M2[l][k]-minCol(k, M2);
}
return M3;
}
//
public int minRow(int l, int M[][])
{
int n=M.length;
int mr=1000000;
for(int j=0; j<n; j++)
{
if((M[l][j]<mr)&&(M[l][j]!=-1))
mr=M[l][j];
}
if(mr==1000000)
mr=0;
return mr;
}
//**
public int minCol(int c, int M[][])
{
int n=M.length;
int mc=1000000;
for(int i=0; i<n; i++)
{
if((M[i][c]<mc)&&(M[i][c]!=-1))
mc=M[i][c];
}
if(mc==1000000)
mc=0;
return mc;
}
//choix de l'arête:
public Arete choixArete(int M[][], ArrayList<Arete>Sp)
{
Arete art=new Arete();
Arete art2=new Arete();
Arete artf=new Arete();
int n=M.length;
artf.l=-1; artf.c=-1;
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
if(M[i][j]!=-1)
{
art.l=i; art.c=j;
art2.c=i; art2.l=j;
if(!Sp.contains(art))
if((!Sp.contains(art2))&&(art.l!=art.c))
{
artf.l=i; artf.c=j;
}
}
if((artf.l==-1)||(artf.c==-1))
return null;
return artf;
}
// avec Arete est l'element choisit de M
public Arete()
{
this.l=-1;
this.c=-1;
}
//m-a-j de la ligne et la colonne de l'élément choisi pour la sol droite
public int[][] updateMatLC(int l, int c, int M[][])
{
int n=M.length;
int M2[][]=M;
if((l!=-1)||(c!=-1))
{
for(int i=0; i<n; i++)
M2[l][i]=-1;
for(int j=0; j<n; j++)
M2[j][c]=-1;
}
M2[c][l]=-1; //
return M2;
}
//m-a-j de l'élément choisi pour l'exploration gauche:
public int[][] updateMatCase(int l, int c, int M[][])
{
int M2[][]=M;
M2=M;
if((l!=-1)||(c!=-1))
M2[l][c]=-1;
M2[c][l]=-1;
return M2;
} |
Partager