Objeto que armazena uma restrição linear no formato lowerBound ≤ Sum(a(i) x(i)) ≤ upperBound
,
em que lowerBound
e upperBound
são constantes, a(i)
são coeficientes
constantes e x(i)
são variáveis (desconhecidas).
O exemplo abaixo cria uma variável x
com valores entre 0
e 5
e gera a restrição 0 ≤ 2 * x ≤ 5
. Isso é feito primeiro criando uma restrição
com o limite inferior 5
e o limite superior 5
. Em seguida, o coeficiente da variável
x
nesta restrição é definido como 2
.
var engine = LinearOptimizationService.createEngine(); // Create a variable so we can add it to the constraint engine.addVariable('x', 0, 5); // Create a linear constraint with the bounds 0 and 10 var constraint = engine.addConstraint(0, 10); // Set the coefficient of the variable in the constraint. The constraint is now: // 0 <= 2 * x <= 5 constraint.setCoefficient('x', 2);
Métodos
Método | Tipo de retorno | Breve descrição |
---|---|---|
setCoefficient(variableName, coefficient) | LinearOptimizationConstraint | Define o coeficiente de uma variável na restrição. |
Documentação detalhada
setCoefficient(variableName, coefficient)
Define o coeficiente de uma variável na restrição. Por padrão, as variáveis têm um coeficiente de 0.
var engine = LinearOptimizationService.createEngine(); // Create a linear constraint with the bounds 0 and 10 var constraint = engine.addConstraint(0, 10); // Create a variable so we can add it to the constraint engine.addVariable('x', 0, 5); // Set the coefficient of the variable in the constraint. The constraint is now: // 0 <= 2 * x <= 5 constraint.setCoefficient('x', 2);
Parâmetros
Nome | Tipo | Descrição |
---|---|---|
variableName | String | o nome da variável para a qual o coeficiente está sendo definido |
coefficient | Number | coeficiente sendo definido |
Retorno
LinearOptimizationConstraint
: é esta restrição de otimização linear.