1
1
2
-
3
2
/**
4
3
* Problema de Programação Linear
5
4
*
@@ -10,11 +9,11 @@ public class PPL {
10
9
private final double COEFICIENTE_INVALIDO = Double .MAX_VALUE ;
11
10
private final int NUMERO_MAXIMO_ITERACOES ;
12
11
13
- private final int MAIOR = 2 ;
14
- private final int MAIOR_IGUAL = 1 ;
15
- private final int IGUAL = 0 ;
16
- private final int MENOR_IGUAL = -1 ;
17
- private final int MENOR = -2 ;
12
+ public static final int MAIOR = 2 ;
13
+ public static final int MAIOR_IGUAL = 1 ;
14
+ public static final int IGUAL = 0 ;
15
+ public static final int MENOR_IGUAL = -1 ;
16
+ public static final int MENOR = -2 ;
18
17
19
18
private boolean maximizacao ; //é um problema de maximização?
20
19
private int qtdeRestricoes ; //quantidade de restrições deste problema
@@ -41,7 +40,11 @@ public class PPL {
41
40
* @param naoNegatividadeMaiorIgual
42
41
* @param naoNegatividadeReais
43
42
*/
44
- public PPL (boolean maximizacao , int qtdeRestricoes , int qtdeVariaveis , double [] funcaoObjetivo , double [][] restricoes , int [] sinalRestricoes , int [] naoNegatividadeMenorIgual , int [] naoNegatividadeMaiorIgual , int [] naoNegatividadeReais ) {
43
+ public PPL (boolean maximizacao , int qtdeRestricoes ,
44
+ int qtdeVariaveis , double [] funcaoObjetivo ,
45
+ double [][] restricoes , int [] sinalRestricoes ,
46
+ int [] naoNegatividadeMenorIgual , int [] naoNegatividadeMaiorIgual ,
47
+ int [] naoNegatividadeReais ) {
45
48
this .maximizacao = maximizacao ;
46
49
this .qtdeRestricoes = qtdeRestricoes ;
47
50
this .qtdeVariaveis = qtdeVariaveis ;
@@ -65,7 +68,8 @@ public PPL(boolean maximizacao, int qtdeRestricoes, int qtdeVariaveis, double[]
65
68
* @param restricoes
66
69
* @param naoNegatividade
67
70
*/
68
- public PPL (String tipo , int qtdeRestricoes , int qtdeVariaveis , String funcaoObjetivo , String [] restricoes , String [] naoNegatividade ) {
71
+ public PPL (String tipo , int qtdeRestricoes , int qtdeVariaveis ,
72
+ String funcaoObjetivo , String [] restricoes , String [] naoNegatividade ) {
69
73
if (tipo .equalsIgnoreCase ("max" )) { //Se for Max, set True.. se não, continue false
70
74
this .maximizacao = true ;
71
75
}
@@ -104,14 +108,14 @@ public void print() {
104
108
System .out .print (" " + restricoes [i ][j ] + "X" + (j + 1 ));
105
109
}
106
110
}
107
- switch (sinalRestricoes [i ]) {
108
- case - 1 :
111
+ switch (getSinalRestricoes () [i ]) {
112
+ case PPL . MENOR_IGUAL :
109
113
System .out .print (" <= " + restricoes [i ][j ]);
110
114
break ;
111
- case 0 :
115
+ case PPL . MAIOR_IGUAL :
112
116
System .out .print (" >= " + restricoes [i ][j ]);
113
117
break ;
114
- case 1 :
118
+ case PPL . IGUAL :
115
119
System .out .print (" = " + restricoes [i ][j ]);
116
120
break ;
117
121
}
@@ -153,7 +157,7 @@ public void print() {
153
157
154
158
private void insertRestricoes (String [] restricoes ) {
155
159
this .restricoes = new double [qtdeRestricoes ][qtdeVariaveis + 1 ];
156
- this .sinalRestricoes = new int [qtdeRestricoes ];
160
+ this .setSinalRestricoes ( new int [qtdeRestricoes ]) ;
157
161
String atual ;
158
162
String numero ;
159
163
char c ;
@@ -185,13 +189,13 @@ private void insertRestricoes(String[] restricoes) {
185
189
} else if (numero .charAt (0 ) == '<' || numero .charAt (0 ) == '>' || numero .charAt (0 ) == '=' ) {
186
190
switch (numero .charAt (0 )) {
187
191
case '<' : //<=
188
- this .sinalRestricoes [i ] = this .MENOR_IGUAL ;
192
+ this .getSinalRestricoes () [i ] = this .getMENOR_IGUAL () ;
189
193
break ;
190
194
case '>' :
191
- this .sinalRestricoes [i ] = this .MAIOR_IGUAL ; //>=
195
+ this .getSinalRestricoes () [i ] = this .getMAIOR_IGUAL () ; //>=
192
196
break ;
193
197
case '=' :
194
- this .sinalRestricoes [i ] = this .IGUAL ; //=
198
+ this .getSinalRestricoes () [i ] = this .getIGUAL () ; //=
195
199
break ;
196
200
}
197
201
numero = "" ;
@@ -310,42 +314,42 @@ public PPL gerarDual() {
310
314
for (int i = 0 ; i < this .qtdeVariaveis ; i ++) {
311
315
if (!isMaximizacao ()) { //PRIMAL DE MAXIMIZACAO
312
316
if (this .naoNegatividadeMenorIgual [i ] == 1 ) {
313
- sinalRestricoesDual [i ] = this .MAIOR_IGUAL ;
317
+ sinalRestricoesDual [i ] = this .getMAIOR_IGUAL () ;
314
318
}
315
319
if (this .naoNegatividadeMaiorIgual [i ] == 1 ) {
316
- sinalRestricoesDual [i ] = this .MENOR_IGUAL ;
320
+ sinalRestricoesDual [i ] = this .getMENOR_IGUAL () ;
317
321
}
318
322
if (this .naoNegatividadeReais [i ] == 1 ) {
319
- sinalRestricoesDual [i ] = this .IGUAL ;
323
+ sinalRestricoesDual [i ] = this .getIGUAL () ;
320
324
}
321
325
} else { //PRIMAL DE MINIMIZACAO
322
326
if (this .naoNegatividadeMenorIgual [i ] == 1 ) {
323
- sinalRestricoesDual [i ] = this .MENOR_IGUAL ;
327
+ sinalRestricoesDual [i ] = this .getMENOR_IGUAL () ;
324
328
}
325
329
if (this .naoNegatividadeMaiorIgual [i ] == 1 ) {
326
- sinalRestricoesDual [i ] = this .MAIOR_IGUAL ;
330
+ sinalRestricoesDual [i ] = this .getMAIOR_IGUAL () ;
327
331
}
328
332
if (this .naoNegatividadeReais [i ] == 1 ) {
329
- sinalRestricoesDual [i ] = this .IGUAL ;
333
+ sinalRestricoesDual [i ] = this .getIGUAL () ;
330
334
}
331
335
}
332
336
}
333
337
//add nao negatividade
334
338
for (int i = 0 ; i < this .qtdeRestricoes ; i ++) {
335
339
if (!isMaximizacao ()) { //PRIMAL DE MAXIMIZACAO
336
- switch (this .sinalRestricoes [i ]) {
337
- case MENOR_IGUAL :
340
+ switch (this .getSinalRestricoes () [i ]) {
341
+ case PPL . MENOR_IGUAL :
338
342
naoNegatividadeMenorIgualDual [i ] = 1 ;
339
343
break ;
340
- case MAIOR_IGUAL :
344
+ case PPL . MAIOR_IGUAL :
341
345
naoNegatividadeMaiorIgualDual [i ] = 1 ;
342
346
break ;
343
- case IGUAL :
347
+ case PPL . IGUAL :
344
348
naoNegatividadeReaisDual [i ] = 1 ;
345
349
break ;
346
350
}
347
351
} else { //PRIMAL DE MINIMIZACAO
348
- switch (this .sinalRestricoes [i ]) {
352
+ switch (this .getSinalRestricoes () [i ]) {
349
353
case MENOR_IGUAL :
350
354
naoNegatividadeMaiorIgualDual [i ] = 1 ;
351
355
break ;
@@ -383,11 +387,7 @@ public void setMaximizacao(boolean maximizacao) {
383
387
* change the state of maximizacao
384
388
*/
385
389
public void changeMaximizacao () {
386
- if (isMaximizacao ()) {
387
- this .maximizacao = false ;
388
- } else {
389
- this .maximizacao = true ;
390
- }
390
+ this .maximizacao = !isMaximizacao ();
391
391
}
392
392
393
393
/**
@@ -495,4 +495,32 @@ public int getNUMERO_MAXIMO_ITERACOES() {
495
495
return NUMERO_MAXIMO_ITERACOES ;
496
496
}
497
497
498
+ public int [] getSinalRestricoes () {
499
+ return sinalRestricoes ;
500
+ }
501
+
502
+ public void setSinalRestricoes (int [] sinalRestricoes ) {
503
+ this .sinalRestricoes = sinalRestricoes ;
504
+ }
505
+
506
+ public int getMAIOR () {
507
+ return MAIOR ;
508
+ }
509
+
510
+ public int getMAIOR_IGUAL () {
511
+ return MAIOR_IGUAL ;
512
+ }
513
+
514
+ public int getIGUAL () {
515
+ return IGUAL ;
516
+ }
517
+
518
+ public int getMENOR_IGUAL () {
519
+ return MENOR_IGUAL ;
520
+ }
521
+
522
+ public int getMENOR () {
523
+ return MENOR ;
524
+ }
525
+
498
526
}
0 commit comments