private void readBOUNDS() { /* type meaning * --------------------------------------------------- * LO lower bound b <= x (< +inf) * UP upper bound (0 <=) x <= b * FX fixed variable x = b * FR free variable -inf < x < +inf * MI lower bound -inf -inf < x (<= 0) * PL upper bound +inf (0 <=) x < +inf * BV binary variable x = 0 or 1 * LI integer variable b <= x (< +inf) * UI integer variable (0 <=) x <= b * SC semi-cont variable x = 0 or l <= x <= b * l is the lower bound on the variable * If none set then defaults to 1*/ //Como se trata de um bloco opcional dos problemas, //Apenas tratarei os tipos LO e UP. Restricao auxRest; string boundType; string boundName; string nomeVariavel; string boundValue; string auxRestName; //sera criada uma nova restricao se a fronteira for valida Desigualdade tipoDesigualdade = Desigualdade.Igual; if (_linha.Equals("BOUNDS")) { _linha = _mpsFile.ReadLine(); while (!_linha.Equals("ENDATA")) { _tokens = GerarTokens(_linha); boundType = _tokens[0]; boundName = _tokens[1]; nomeVariavel = _tokens[2]; boundValue = _tokens[3]; if (boundType.Equals("LO")) { tipoDesigualdade = Desigualdade.MaiorOuIgual; } else if (boundType.Equals("UP")) { tipoDesigualdade = Desigualdade.MenorOuIgual; } auxRest = _funcao.AddRestricao(); //Configurar nova restricao _funcao.AddVariavelRestricao(auxRest.Nome, nomeVariavel, 1.0); _funcao.SetDesigualdadeRestricao(auxRest.Nome, tipoDesigualdade); _funcao.SetTermoLivreRestricao(auxRest.Nome, double.Parse(boundValue, _culture)); _linha = _mpsFile.ReadLine(); } } }
private void GerarRestricoes() { Restricao auxRest = null; int custoRest = 0; int coeficienteVar = 0; for (int i = 0; i < _qtdRestricoes; i++) { custoRest = 0; auxRest = _funcaoObj.AddRestricao(PREFIXO_RESTRICAO + i); auxRest.Desigualdade = GerarDesigualdade(); foreach (var variavel in _variaveis) { if (GerarBool(_densidadeMatriz)) { coeficienteVar = _rnd.Next(-9, 9); auxRest.AddVariavel(variavel.Nome, coeficienteVar); custoRest += coeficienteVar * variavel.ValorCusto; } } //calcular termo livre em funcao do custo acumulado para a restricao auxRest.TermoLivre = GerarTermoLivreFactivelRestricao(custoRest, auxRest.Desigualdade); } }