.. _secMATLABrefVariableInstance: VariableInstance ================ .. mat:class:: VariableInstance The VariableInstance object stores the information regarding a specific instance of a variable. The instances can be accessed through the function :mat:meth:`Variable.get` of the parent entity. value() ------- .. mat:classmethod:: VariableInstance.value() **Syntax** ``v = value()`` **Description** ``v = value()`` Get the current value of the variable instance **Output Arguments** ``v`` The current value of the variable instance **Example** Create a variable x, get an instance and display its value. .. code-block:: matlab ampl.eval('var x{1..2};'); x = ampl.getVariable('x'); instance = x.get(1); instance.value gives:: ans = 0 setValue(v) ----------- .. mat:classmethod:: VariableInstance.setValue() **Syntax** ``setValue(v)`` **Description** ``setValue(v)`` Assigns the specified value to the variable. Equivalent to the AMPL code:: var x; let x := v; **Input Arguments** ``v`` The value to be assigned **Example** Create a variable x and sets its initial value. Then displays it: .. code-block:: matlab ampl.eval('var x{1..2};'); x = ampl.getVariable('x'); instance = x.get(1); instance.setValue(4); instance.value gives:: ans = 4 dual ---- .. mat:classmethod:: VariableInstance.dual() **Syntax** ``v = dual`` **Description** ``dual`` Get the current dual value of the variable instance. **Output Arguments** ``v`` The dual value of the instance **Example** Create a variable x, get an instance and display its dual value. .. code-block:: matlab ampl.eval('var x{1..2};'); x = ampl.getVariable('x'); instance = x.get(1); instance.dual gives:: ans = 0 lb -- .. mat:classmethod:: VariableInstance.lb() **Syntax** ``v = lb`` **Description** ``lb`` Get the current lower bound of the variable. See :ref:`secVariableSuffixesNotes`. **Output Arguments** ``v`` The lower bound of the variable **Example** Create an indexed variable x (using :mat:meth:`AMPL.eval`) and get the value of the lower bound. .. code-block:: matlab ampl.eval('var x{1..3};'); x = ampl.getVariable('x'); instance = x.get(1); v = instance.lb gives:: v = 0 ub -- .. mat:classmethod:: VariableInstance.ub() **Syntax** ``v = ub`` **Description** ``ub`` Get the current upper bound of the instance. See :ref:`secVariableSuffixesNotes`. **Output Arguments** ``v`` The upper bound of the instance **Example** Create an indexed variable y (:mat:meth:`AMPL.eval`) and get the value of one instance. .. code-block:: matlab ampl.eval('var x{1..3};'); x = ampl.getVariable('x'); instance = x.get(1); v = instance.lb gives:: v = 0 fix --- .. mat:classmethod:: VariableInstance.fix() **Syntax** ``fix`` ``fix(value)`` **Description** ``fix`` Fix this instance to its current value ``fix(value)`` Fix this instance to the specified value **Example** Create a scalar variable x and an indexed variable y (using :mat:meth:`AMPL.eval`), fix a few values, solve and unfix them .. code-block:: matlab ampl.eval('var x<=3; var y{1..3}<=4;'); ampl.eval('maximize z: x + sum{i in 1..3} y[i];'); x = ampl.getVariable('x'); y = ampl.getVariable('y'); x.fix(1); % fix variables y.get(2).fix(2); ampl.solve; % solve x.display % display solution y.display x.unfix; % unfix variables y.unfix; ampl.solve; % solve and display x.display % display solution y.display gives:: ans = x = 1 ans = y [*] := 1 4 2 2 3 4 ; ans = x = 3 ans = y [*] := 1 4 2 4 3 4 ; unfix ----- .. mat:classmethod:: VariableInstance.unfix() **Syntax** ``unfix`` **Description** ``unfix`` Unfix this instance **Example** Create a scalar variable x and an indexed variable y (using :mat:meth:`AMPL.eval`), fix a few values, solve and unfix them .. code-block:: matlab ampl.eval('var x<=3; var y{1..3}<=4;'); ampl.eval('maximize z: x + sum{i in 1..3} y[i];'); x = ampl.getVariable('x'); y = ampl.getVariable('y'); x.fix(1); % fix variables y.get(2).fix(2); ampl.solve; % solve x.display % display solution y.display x.unfix; % unfix variables y.unfix; ampl.solve; % solve and display x.display % display solution y.display gives:: ans = x = 1 ans = y [*] := 1 4 2 2 3 4 ; ans = x = 3 ans = y [*] := 1 4 2 4 3 4 ;