美文网首页Python与OR
OR-tools中常见函数说明

OR-tools中常见函数说明

作者: 白晓寒星 | 来源:发表于2019-08-07 10:10 被阅读0次
    from ortools.sat.python import cp_model
    
    model = cp_model.CpModel()
    

    1.model.NewIntVar:创建一个整数变量。
    NewIntVar(lb, ub, name) method of ortools.sat.python.cp_model.CpModel instance
    Create an integer variable with domain [lb, ub].
    2.model.NewIntervalVar:创建一个区间变量
    NewIntervalVar(start, size, end, name) method of ortools.sat.python.cp_model.CpModel instance
    Creates an interval variable from start, size, and end.
    区间变量,即变量的取值在一定的范围内。
    3.model.NewBoolVar:创建一个0-1整数变量
    NewBoolVar(name) method of ortools.sat.python.cp_model.CpModel instance
    Creates a 0-1 variable with the given name.
    4.model.AddCumulative:添加一个累积约束
    AddCumulative(intervals, demands, capacity) method of ortools.sat.python.cp_model.CpModel instance
    Adds Cumulative(intervals, demands, capacity).累积的
    This constraint enforces that:
    for all t:
    sum(demands[i]
    if (start(intervals[t]) <= t < end(intervals[t])) and
    (t is present)) <= capacity
    5.model.AddNoOverlap:确保区间变量不会有交集。
    AddNoOverlap(interval_vars) method of ortools.sat.python.cp_model.CpModel instance
    Adds NoOverlap(interval_vars).交叠Overlap
    A NoOverlap constraint ensures that all present intervals do not overlap
    in time.
    6.model.AddAllDifferent:每个变量的取值都不能相同。
    AddAllDifferent(variables) method of ortools.sat.python.cp_model.CpModel instance
    Adds AllDifferent(variables).
    # 每一个变量都必须取不同的值,不能相同。
    This constraint forces all variables to have different values.
    7.model.AddAbsEquality:变量的绝对值等于一个数
    AddAbsEquality(target, var) method of ortools.sat.python.cp_model.CpModel instance
    Adds target == Abs(var).变量的绝对值等于一个数
    8.model.AddImplication:添加一个不等约束
    AddImplication(a, b) method of ortools.sat.python.cp_model.CpModel instance
    Adds a => b.

    相关文章

      网友评论

        本文标题:OR-tools中常见函数说明

        本文链接:https://www.haomeiwen.com/subject/acbndctx.html