'Set a variable *name* to *value*. The actual set value is returned (in
some cases, the value may be cast into another type).
If *value* is None, then the value is left to be determined in the
future. At any time, the value may be re-assigned arbitrarily unless
a constraint is given.
If *constraint* is True (the default), then supplying a value that
violates a previously specified constraint will raise an exception.
If *constraint* is \'fixed\', then the value is set (if provided) and
the variable will not be updated automatically in the future.
If *constraint* is a tuple, then the value is constrained to be within the
given (min, max). Either constraint may be None to disable
it. In some cases, a constraint cannot be satisfied automatically,
and the user will be forced to resolve the constraint manually.
If *constraint* is None, then any constraints are removed for the variable.'

def set(self, name, value=None, constraint=True):

    var = self._vars[name]
    if (constraint is None):
        if ('n' not in var[3]):
            raise TypeError(("Empty    constraints    not    allowed    for    '%s'" % name))
        var[2] = constraint
    elif (constraint == 'fixed'):
        if ('f' not in var[3]):
            raise TypeError(("Fixed    constraints    not    allowed    for    '%s'" % name))
        var[2] = constraint
    elif isinstance(constraint, tuple):
        if ('r' not in var[3]):
            raise TypeError(("Range    constraints    not    allowed    for    '%s'" % name))
        assert (len(constraint) == 2)
        var[2] = constraint
    elif (constraint is not True):
        raise TypeError(("constraint    must    be    None,    True,    'fixed',    or    tuple.    (got    %s)" % constraint))
    if (var[1] is np.ndarray):
        value = np.array(value, dtype=float)
    elif ((var[1] in (int, float, tuple)) and (value is not None)):
        value = var[1](value)
    if ((constraint is True) and (not self.check_constraint(name, value))):
        raise ValueError(('Setting    %s    =    %s    violates    constraint    %s' % (name, value, var[2])))
    if (var[0] is not None):
        self.resetUnfixed()
    var[0] = value
    return value
