Returns the existing internal solver index for a variable or creates a new one if the variable is yet unknown.
@param var the variable
@return the (old or new) internal variable index
175858
public int getOrCreateVarIndex(final Variable var) {
        Integer index = this.name2idx.get(var.name());
        if (index == null) {
            index = this.name2idx.size() + 1;
            this.name2idx.put(var.name(), index);
            this.idx2name.put(index, var.name());
        }
        return index;
    }
1027669
def add_var(self, var):
        
        if var.name in [v.name for v in self.vars]:
            logger.error("Variable set named '%s' already exists." % var.name)
            return

        var.i1 = self.var_N
        var.iN = self.var_N + var.N - 1
        self.vars.append(var)
843466
public static String get(VariableElement variable) {
    StringBuilder result = new StringBuilder();
    AnnotationMirror qualifier = getQualifier(variable.getAnnotationMirrors());
    if (qualifier != null) {
      qualifierToString(qualifier, result);
    }
    typeToString(variable.asType(), result, '$');
    return result.toString();
  }
505402
private IntVar getEarlyVar() {
        IntVar earlyVar = null;
        for (int i = stays.nextSetBit(0); i >= 0; i = stays.nextSetBit(i + 1)) {
            if (starts[i] != null && !starts[i].isInstantiated()) {
                if (earlyVar == null) {
                    earlyVar = starts[i];
                } else {
                    if (earlyVar.getLB() > starts[i].getLB()) {
                        earlyVar = starts[i];
                    }
                }
            }
        }
        return earlyVar;
    }
835081
def isel_variable_and_index(
    name: Hashable,
    variable: Variable,
    index: pd.Index,
    indexers: Mapping[Any, Union[slice, Variable]],
) -> Tuple[Variable, Optional[pd.Index]]:
    """"""
    if not indexers:
        # nothing to index
        return variable.copy(deep=False), index

    if len(variable.dims) > 1:
        raise NotImplementedError(
            'indexing multi-dimensional variable with indexes is not '
            'supported yet')

    new_variable = variable.isel(indexers)

    if new_variable.dims != (name,):
        # can't preserve a index if result has new dimensions
        return new_variable, None

    # we need to compute the new index
    (dim,) = variable.dims
    indexer = indexers[dim]
    if isinstance(indexer, Variable):
        indexer = indexer.data
    new_index = index[indexer]
    return new_variable, new_index
1048219
def store_variable(var)
      # Update the variable to track the index in the model
      index = @var_count + 1
      var.model = self
      var.index = index
      var.freeze
      @var_count += 1

      ret = LPSolve.add_columnex @ptr, 0, nil, nil
      fail if ret != 1

      # Set variable properties
      set_variable_type index, var.type

      ret = LPSolve.set_col_name(@ptr, index, var.name)
      fail if ret != 1

      ret = LPSolve.set_obj(@ptr, index, var.coefficient)
      fail if ret != 1

      set_variable_bounds index, var.lower_bound, var.upper_bound

      @variables << var
    end
658132
private JMFType findVariantChildByName(JSVariant var, String name) {
    for (int i = 0; i < var.getCaseCount(); i++) {
      JMFType theCase = getEffectiveType(var.getCase(i));
      String caseName = theCase.getFeatureName();
      if (caseName != null && caseName.equals(name))
        return theCase;
    }
    return null;
  }
1020903
def _ResolutionOrder(self, variables_to_solve):
        
#    Gp=nx.DiGraph()
#
#    for i in range(nvar):
#        Gp.add_node('v'+str(i),bipartite=0)
#
#    for i in range(neq):
#        Gp.add_node('e'+str(i),bipartite=1)
#        for j in range(nvar):
#            if Mo[i,j]==1:
#                Gp.add_edge('e'+str(i),'v'+str(j))

        Gp = nx.DiGraph()
        for variable in self.variables:
            Gp.add_node(variable, bipartite=0)
        for block in self.blocks:
            for iov, output_variable in enumerate(block.outputs):
                Gp.add_node((block, iov), bipartite=1)
                Gp.add_edge((block, iov), output_variable)
                Gp.add_edge(output_variable, (block, iov))
                for input_variable in block.inputs:
                    if not isinstance(input_variable, Signal):
                        Gp.add_edge(input_variable, (block, iov))

    #    for n1,n2 in M.items():
    #        Gp.add_edge(n1,n2)

        sinks = []
        sources = []
        for node in Gp.nodes():
            if Gp.out_degree(node) == 0:
                sinks.append(node)
            elif Gp.in_degree(node) == 0:
                sources.append(node)

        G2 = sources[:]
        for node in sources:
            for node2 in nx.descendants(Gp, node):
                if node2 not in G2:
                    G2.append(node2)

        if G2 != []:
            print(G2)
            raise ModelError('Overconstrained variables')

        G3 = sinks[:]
        for node in sinks:
            for node2 in nx.ancestors(Gp, node):
                if node2 not in G3:
                    G3.append(node2)

        if G3 != []:
            raise ModelError('Underconstrained variables')

#        vars_resolvables=[]
#        for var in vars_resoudre:
#            if not 'v'+str(var) in G2+G3:
#                vars_resolvables.append(var)


#        G1=Gp.copy()
#        G1.remove_nodes_from(G2+G3)
#
#        M1=nx.bipartite.maximum_matching(G1)
#        G1p=nx.DiGraph()
#
#        G1p.add_nodes_from(G1.nodes())
#        for e in G1.edges():
#            # equation vers variable
#            if e[0][0]=='v':
#                G1p.add_edge(e[0],e[1])
#            else:
#                G1p.add_edge(e[1],e[0])
#    #    print(len(M))
#        for n1,n2 in M1.items():
#    #        print(n1,n2)
#            if n1[0]=='e':
#                G1p.add_edge(n1,n2)
#            else:
#                G1p.add_edge(n2,n1)

        scc = list(nx.strongly_connected_components(Gp))
    #    pos=nx.spring_layout(G1p)
    #    plt.figure()
    #    nx.draw(G1p,pos)
    #    nx.draw_networkx_labels(G1p,pos)
#        print(scc)
        if scc != []:
            C = nx.condensation(Gp, scc)
            isc_vars = []
            for isc, sc in enumerate(scc):
                for var in variables_to_solve:
                    if var in sc:
                        isc_vars.append(isc)
                        break
            ancestors_vars = isc_vars[:]

            for isc_var in isc_vars:
                for ancetre in nx.ancestors(C, isc_var):
                    if ancetre not in ancestors_vars:
                        ancestors_vars.append(ancetre)

            order_sc = [sc for sc in nx.topological_sort(
                C) if sc in ancestors_vars]
            order_ev = []
            for isc in order_sc:
                # liste d'équations et de variables triées pour être séparées
                evs = list(scc[isc])
#                print(evs)
#                levs=int(len(evs)/2)
                eqs = []
                var = []
                for element in evs:
                    if type(element) == tuple:
                        eqs.append(element)
                    else:
                        var.append(element)
                order_ev.append((len(eqs), eqs, var))

            return order_ev

        raise ModelError
177070
public T get(String variable, String frame, int iteration, FrameIter parentFrameIter, boolean enforceExistence) {
        //TODO eventually we'll cache and reuse VarId objects here to avoid garbage generation on lookup etc
        VarId varId = newVarId(variable, frame, iteration, parentFrameIter);
        T out = nodeOutputs.get(varId);
        if(enforceExistence) {
            Preconditions.checkNotNull(out, "No output found for variable %s (frame %s, iteration %s)", variable, frame, iteration);
        }
        return out;
    }
572657
public SortedSet<Variable> variables() {
    if (this.variables == null) {
      this.variables = new TreeSet<>();
      for (final Formula f : this.formulas)
        this.variables.addAll(f.variables());
    }
    return this.variables;
  }
1165614
@Override
	public String onVariable(String variable) {
		String value = null;
		if(variables != null && variables.containsKey(variable)) {
			Object val = variables.get(variable);
			value = (val != null) ? val.toString() : null;
		}
		return value;
	}
1242770
public String getVariableShortName(VariableElement var) {
    String baseName = getVariableBaseName(var);
    if (var.getKind().isField() && !ElementUtil.isGlobalVar(var)) {
      return baseName + '_';
    }
    return baseName;
  }
1131778
public SDVariable var(@NonNull String name, @NonNull VariableType variableType, WeightInitScheme weightInitScheme,
                             org.nd4j.linalg.api.buffer.DataType dataType, long... shape) {
        if (variables.containsKey(name) && variables.get(name).getVariable().getArr() != null)
            throw new IllegalArgumentException("Another variable with the name " + name + " already exists.");

        if (name == null || name.length() < 1)
            name = getNewVarName();


        SDVariable ret = new SDVariable(name, variableType, this, shape, dataType, weightInitScheme);
        addVariable(ret);

        if(variableType == VariableType.PLACEHOLDER){
            setOriginalPlaceHolderShape(name, shape);
            putShapeForVarName(name, shape);
        }
        return ret;
    }
632621
public static int[] getIndexesOfFreeVariable(Expression2 expression, String variableName) {
    List<Integer> indexes = Lists.newArrayList();
    ScopeSet scopes = getScopes(expression);
    for (int i = 0; i < expression.size(); i++) {
      Scope scope = scopes.getScope(i);
      String varName = getFreeVariable(expression, i, scope);
      if (varName != null && varName.equals(variableName)) {
        indexes.add(i);
      }
    }
    return Ints.toArray(indexes);
  }
432043
public SDVariable addVariable(SDVariable variable) {
        Preconditions.checkState(variable.getSameDiff() == this, "Samediff instance must be the same.");

        if (variables.containsKey(variable.getVarName()) && !variables.get(variable.getVarName()).getVariable().equals(variable)) {
            throw new IllegalArgumentException("Variable already found with variable opName " + variable.getVarName());
        }

        Preconditions.checkState(variable.getSameDiff() == this, "Same diff instance for variable must be the same!");
        variables.put(variable.getVarName(), Variable.builder().name(variable.getVarName()).variable(variable).build());
        return variable;
    }
929811
protected Object lookupVar(JsonNode node, String var) {
		List<? extends JsonNode> children = node.getChildren(var);
		if (children.size()>1) { // multiple with name, treat as list of values
			List<String> result = new ArrayList<String>();
			for (JsonNode child : children) {
				result.add(child.getValue());
			}
			return result;
		} else if (children.size()==1) {
			JsonNode child = children.get(0);
			List<String> attributeNames = child.getAttributeNames();
			Collections.sort(attributeNames);

			if (attributeNames.size()==0) { // treat child as the attribute value
				return child.getValue();
			} else { // treat child as object with map values
				Map<String, String> result = new LinkedHashMap<String, String>();
				for (String attrName : attributeNames) {
					result.put(attrName, child.getAttribute(attrName));
				}
				return result;
			}
		} else { // return null
			return null;
		}
	}
1263308
public Concept getConcept(Variable var) {
        var = equivalentVars.componentOf(var);
        assert var != null;

        @Nullable Concept concept = concepts.get(var);

        if (concept == null) {
            @Nullable ConceptBuilder builder = conceptBuilders.remove(var);

            if (builder != null) {
                concept = buildConcept(var, builder);
            }
        }

        if (concept != null) {
            return concept;
        }

        LOG.debug("Could not build concept for {}\nconcepts = {}\nconceptBuilders = {}", var, concepts, conceptBuilders);

        throw GraqlQueryException.insertUndefinedVariable(printableRepresentation(var));
    }