Optimize
Find variable bindings that maximize or minimize a specific objective.
Concept
The Optimize pragmatic extends constraint solving. Instead of just finding any valid assignment, it searches for the assignment that produces the highest or lowest value for a given objective function (an attribute or an aggregation).
Syntax
Maximize <Objective> [Subject to <Constraints>]. Minimize <Objective> [Subject to <Constraints>].
Examples
// Direct Attribute Optimization
Maximize the price of ?product
Subject to:
?product is a Laptop.
?product is in-stock.
// Aggregation Optimization
Minimize the total weight of ?route
Subject to:
?route is a DeliveryPath.
?route is active.
Objective Functions
The objective must evaluate to a numeric value:
- Direct Attribute:
Maximize the capacity of ?server.(Requires a variable binding). - Aggregation:
Minimize the sum of weight of ?items.(Supportstotal of,sum of,average of,number of).
Execution Logic
1. Constraint Resolution: The `Subject to` clause is converted into a constraint satisfaction problem (same as Solve).
2. Evaluation: For each valid variable assignment, the objective function is computed.
3. Selection: The system tracks and returns the solution(s) with the optimal score.
Reference
Defined in DS23 - Optimization.