DyPDL
A library for Dynamic Programming Description Language (DyPDL).
Examples
Example to model TSPTW.
use *;
// TSPTW instance.
// 0 is the depot, and 1, 2, and 3 are customers.
let n_customers = 4;
// Beginnings of time windows.
let ready_time = vec!;
// Ends of time windows.
let due_date = vec!;
// Travel time.
let distance_matrix = vec!;
// Minimization and integer cost by default.
let mut model = default;
// Define an object type.
let customer = model.add_object_type.unwrap;
// Define state variables.
// Unvisited customers, initially 1, 2, and 3.
let unvisited = model.create_set.unwrap;
let unvisited = model.add_set_variable.unwrap;
// Current location, initially 0.
let location = model.add_element_variable.unwrap;
// Current time, less is better, initially 0.
let time = model.add_integer_resource_variable.unwrap;
// Define tables of constants.
let ready_time: = model.add_table_1d.unwrap;
let due_date: = model.add_table_1d.unwrap;
let distance: = model.add_table_2d.unwrap;
// Define transitions.
let mut visits = vec!;
// Returning to the depot;
let mut return_to_depot = new;
// The cost is the sum of the travel time and the cost of the next state.
return_to_depot.set_cost;
// Update the current location to the depot.
return_to_depot.add_effect.unwrap;
// Increase the current time.
return_to_depot.add_effect.unwrap;
// Add the transition to the model.
// When this transition is applicable, no need to consider other transitions.
model.add_forward_forced_transition;
visits.push;
for j in 1..n_customers
// Define a base case.
// If all customers are visited and the current location is the depot, the cost is 0.
let is_depot = comparison_e;
model.add_base_case.unwrap;
// Define redundant information, which is possibly useful for a solver.
// Define state constraints.
for j in 1..n_customers
// Define a dual bound.
// The minimum distance to each customer.
let min_distance_to = distance_matrix.iter
.enumerate
.map.collect;
let min_distance_to: = model.add_table_1d.unwrap;
let to_depot: IntegerExpression = is_depot.if_then_else;
let dual_bound: IntegerExpression = min_distance_to.sum + to_depot;
model.add_dual_bound.unwrap;
// Solution.
let solution = ;
// Solution cost.
let cost = 14;
// Verify the solution.
assert!;