约束分层
原能力
分开硬限制、偏好和仍待确认的条件,减少把未知当作允许的情况。(细化版 p.16–17)
首选项目
Open Policy Agent(Apache-2.0)。 Open Policy Agent
匹配范围
规则求值加硬约束建模,分别承载筛选与求解。
源码
Open Policy Agent · func (pq PreparedEvalQuery) Eval(
v1/rego/rego.go · 608–621 行。 在 GitHub 查看源码 · 许可证与声明
源码片段
func (pq PreparedEvalQuery) Eval(ctx context.Context, options ...EvalOption) (ResultSet, error) {
ectx, finish, err := pq.newEvalContext(ctx, options)
if err != nil {
return nil, err
}
defer finish(ctx)
ectx.compiledQuery = pq.r.compiledQueries[evalQueryType]
return pq.r.eval(ctx, ectx)
}
// PreparedPartialQuery holds the prepared Rego state that has been pre-processed
// for partial evaluations.
- // Copyright 2017 The OPA Authors. All rights reserved.
CVXPY · class Problem
cvxpy/problems/problem.py · 135–148 行。 在 GitHub 查看源码 · 许可证与声明
源码片段
class Problem(u.Canonical):
"""A convex optimization problem.
Problems are immutable, save for modification through the specification
of :class:`~cvxpy.expressions.constants.parameters.Parameter`
Arguments
---------
objective : Minimize or Maximize
The problem's objective.
constraints : iterable
The constraints on the problem variables.
"""
- Copyright 2013 Steven Diamond, 2017 Akshay Agrawal
实现与验收要点
确定偏好/硬限制/待确认,未知需安全处理。