'Maps each variable to a horizontal offset.
Parameters
objective : LinOp
The canonicalized objective.
constraints : list
The canonicalized constraints.
nonlinear : list
Non-linear constraints for CVXOPT.
Returns
tuple
(map of variable to offset, length of variable vector)'

@staticmethod
def get_var_offsets(objective, constraints, nonlinear):

    vars_ = lu.get_expr_vars(objective)
    for constr in constraints:
        vars_ += lu.get_expr_vars(constr.expr)
    for constr in nonlinear:
        for nonlin_var in constr.variables():
            vars_ += lu.get_expr_vars(nonlin_var)
    var_offsets = OrderedDict()
    var_names = list(set(vars_))
    var_names.sort(key=(lambda id_and_size: id_and_size[0]))
    var_sizes = {}
    vert_offset = 0
    for (var_id, var_size) in var_names:
        var_sizes[var_id] = var_size
        var_offsets[var_id] = vert_offset
        vert_offset += (var_size[0] * var_size[1])
    return (var_offsets, var_sizes, vert_offset)
