mirror of
https://github.com/tig-foundation/tig-monorepo.git
synced 2026-02-21 10:27:49 +08:00
Update knapsack and vehicle_routing docs with multi sub-instances.
This commit is contained in:
parent
07eaa65fa9
commit
0781a0fdae
@ -8,7 +8,7 @@ The quadratic knapsack problem is one of the most popular variants of the single
|
||||
For our challenge, we use a version of the quadratic knapsack problem with configurable difficulty, where the following two parameters can be adjusted in order to vary the difficulty of the challenge:
|
||||
|
||||
- Parameter 1: $num\textunderscore{ }items$ is the number of items from which you need to select a subset to put in the knapsack.
|
||||
- Parameter 2: $better\textunderscore{ }than\textunderscore{ }baseline \geq 1$ is the factor by which a solution must be better than the baseline value.
|
||||
- Parameter 2: $better\textunderscore{ }than\textunderscore{ }baseline \geq 1$ (see Our Challenge)
|
||||
|
||||
The larger the $num\textunderscore{ }items$, the more number of possible $S_{knapsack}$, making the challenge more difficult. Also, the higher $better\textunderscore{ }than\textunderscore{ }baseline$, the less likely a given $S_{knapsack}$ will be a solution, making the challenge more difficult.
|
||||
|
||||
@ -25,30 +25,41 @@ We impose a weight constraint $W(S_{knapsack}) <= 0.5 \cdot W(S_{all})$, where t
|
||||
|
||||
# Example
|
||||
|
||||
Consider an example of a challenge instance with `num_items=4` and `better_than_baseline = 1.50`. Let the baseline value be 46:
|
||||
Consider an example of a challenge instance with `num_items=4`:
|
||||
|
||||
```
|
||||
weights = [39, 29, 15, 43]
|
||||
individual_values = [0, 14, 0, 75]
|
||||
interaction_values = [ 0, 0, 0, 0
|
||||
0, 0, 32, 0
|
||||
0, 32, 0, 0
|
||||
0, 0, 0, 0]
|
||||
weights = [39, 29, 15, 43, 3]
|
||||
individual_values = [0, 14, 0, 75, 10]
|
||||
interaction_values = [ 0, 0, 0, 0, 5
|
||||
0, 0, 32, 0, 10
|
||||
0, 32, 0, 0, 0
|
||||
0, 0, 0, 0, 0
|
||||
5, 10, 0, 0, 0 ]
|
||||
max_weight = 63
|
||||
min_value = baseline*better_than_baseline = 69
|
||||
baseline_value = 100
|
||||
```
|
||||
The objective is to find a set of items where the total weight is at most 63 but has a total value of at least 69.
|
||||
|
||||
Now consider the following selection:
|
||||
|
||||
```
|
||||
selected_items = [2, 3]
|
||||
selected_items = [2, 3, 4]
|
||||
```
|
||||
|
||||
When evaluating this selection, we can confirm that the total weight is less than 63, and the total value is more than 69, thereby this selection of items is a solution:
|
||||
When evaluating this selection, we can confirm that the total weight is less than 63, and the total value is 127:
|
||||
|
||||
* Total weight = 15 + 43 = 58
|
||||
* Total value = 0 + 75 + 0 = 75
|
||||
* Total weight = 15 + 43 + 3 = 61
|
||||
* Interaction values = (2,3) + (2,4) + (3,4) = 32 + 10 + 0 = 42
|
||||
* Individual values = 0 + 75 + 10 = 85
|
||||
* Total value = 42 + 85 = 127
|
||||
|
||||
This selection is 27% better than the baseline:
|
||||
```
|
||||
better_than_baseline = (total_value - baseline_value) / baseline_value
|
||||
= (127 - 100) / 100
|
||||
= 0.27
|
||||
```
|
||||
|
||||
# Our Challenge
|
||||
In TIG, the baseline value is determined by a two-stage approach. First, items are selected based on their value-to-weight ratio, including interaction values, until the capacity is reached. Then, a tabu-based local search refines the solution by swapping items to improve value while avoiding reversals, with early termination for unpromising swaps.
|
||||
|
||||
Each instance of TIG's knapsack problem contains 16 random sub-instances with their own baseline selection & baseline value. For each sub-instance, the total value of your selection is used to calculate a `better_than_baseline`. Your average `better_than_baseline` over the sub-instances must be greater than or equal to the specified difficulty `better_than_baseline`. Please see the challenge code for a precise specification.
|
||||
@ -21,12 +21,12 @@ VRPTW involves determining a set of cost-effective routes for a fleet of identic
|
||||
The following is an example of the Vehicle Routing Problem with Time Windows with configurable difficulty. Two parameters can be adjusted in order to vary the difficulty of the challenge instance:
|
||||
|
||||
- Parameter 1: $num\textunderscore{ }nodes$ is the number of customers (plus 1 depot) which are distributed across a grid of 1000x1000 with the depot at the centre (500, 500).
|
||||
- Parameter 2: $better\textunderscore{ }than\textunderscore{ }baseline$ is the factor by which a solution must be better than the baseline value [link TIG challenges for explanation of baseline value].
|
||||
- Parameter 2: $better\textunderscore{ }than\textunderscore{ }baseline$ (see Our Challenge)
|
||||
|
||||
Demand of each customer is selected independently and uniformly at random from the range [1, 35]. Each customer is assigned a time window between which they must be serviced. Service duration is set to a fixed value of 10 time units per customer. The maximum capacity of each vehicle is set to 200.
|
||||
|
||||
|
||||
Consider an example instance with `num_nodes=8` and `better_than_baseline=0.8` with the `baseline=3875`:
|
||||
Consider an example instance with `num_nodes=8`:
|
||||
|
||||
```
|
||||
# A sample generated example
|
||||
@ -44,10 +44,10 @@ CUST NO. XCOORD. YCOORD. DEMAND READY TIME DUE TIME SERVICE TIME
|
||||
|
||||
max_capacity = 200 # total demand for each route must not exceed this number
|
||||
fleet_size = 4 # the total number of routes must not exceed this number
|
||||
max_total_distance = baseline*better_than_baseline = 3100 # (better_than_baseline * baseline) routes must have total distance under this number to be a solution
|
||||
baseline_total_distance = 3875
|
||||
```
|
||||
|
||||
The depot is the first node (node 0) with demand 0. The vehicle capacity is set to 200 and the fleet capacity to 4. In this example, routes must have a total distance of 3100 or less to be a solution.
|
||||
The depot is the first node (node 0) with demand 0. The vehicle capacity is set to 200 and the fleet capacity to 4.
|
||||
|
||||
Now consider the following routes:
|
||||
|
||||
@ -73,8 +73,17 @@ When evaluating these routes, each route has demand less than 200, the number of
|
||||
* Distance = 130 + 263 + 357 = 750
|
||||
* Total Distance = 1144 + 1180 + 750 = 3074
|
||||
|
||||
These routes are 20.6% better than the baseline:
|
||||
```
|
||||
better_than_baseline = (baseline_total_distance - total_distance) / baseline_total_distance
|
||||
= (3875 - 3074) / 3875
|
||||
= 0.206
|
||||
```
|
||||
|
||||
## Our Challenge
|
||||
In TIG, the baseline route is determined by using Solomon's I1 insertion heuristic that iteratively inserts customers into routes based on a cost function that balances distance and time constraints. The routes are built one by one until all customers are served. The goal is to produce a solution better than the baseline’s total distance by at least the specified factor (`better_than_baseline`), while ensuring all VRPTW constraints are satisfied. Please see the challenge code for a precise specification.
|
||||
In TIG, the baseline route is determined by using Solomon's I1 insertion heuristic that iteratively inserts customers into routes based on a cost function that balances distance and time constraints. The routes are built one by one until all customers are served.
|
||||
|
||||
Each instance of TIG's vehicle routing problem contains 16 random sub-instances with their own baseline routes & baseline distance. For each sub-instance, the total distance of your routes is used to calculate a `better_than_baseline`. Your average `better_than_baseline` over the sub-instances must be greater than the specified difficulty `better_than_baseline`. Please see the challenge code for a precise specification.
|
||||
|
||||
## Applications
|
||||
* **Logistics & Delivery Services:** Optimizes parcel and ship routing by ensuring vehicles meet customer and operational time constraints, reducing operational costs and environmental impact [^1].
|
||||
|
||||
@ -112,8 +112,10 @@ impl crate::ChallengeTrait<Solution, Difficulty, 2> for Challenge {
|
||||
.enumerate()
|
||||
{
|
||||
match sub_instance.verify_solution(&sub_solution) {
|
||||
Ok(total_value) => better_than_baselines
|
||||
.push(total_value as f64 / sub_instance.baseline_value as f64 - 1.0),
|
||||
Ok(total_value) => better_than_baselines.push(
|
||||
(total_value as f64 - sub_instance.baseline_value as f64)
|
||||
/ sub_instance.baseline_value as f64,
|
||||
),
|
||||
Err(e) => return Err(anyhow!("Instance {}: {}", i, e.to_string())),
|
||||
}
|
||||
}
|
||||
@ -361,15 +363,7 @@ impl SubInstance {
|
||||
let selected_items_vec: Vec<usize> = selected_items.into_iter().collect();
|
||||
let total_value =
|
||||
calculate_total_value(&selected_items_vec, &self.values, &self.interaction_values);
|
||||
if total_value < self.baseline_value {
|
||||
Err(anyhow!(
|
||||
"Total value ({}) does not reach minimum value ({})",
|
||||
total_value,
|
||||
self.baseline_value
|
||||
))
|
||||
} else {
|
||||
Ok(total_value)
|
||||
}
|
||||
Ok(total_value)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -117,7 +117,8 @@ impl crate::ChallengeTrait<Solution, Difficulty, 2> for Challenge {
|
||||
{
|
||||
match sub_instance.verify_solution(&sub_solution) {
|
||||
Ok(total_distance) => better_than_baselines.push(
|
||||
1.0 - total_distance as f64 / sub_instance.baseline_total_distance as f64,
|
||||
(sub_instance.baseline_total_distance as f64 - total_distance as f64)
|
||||
/ sub_instance.baseline_total_distance as f64,
|
||||
),
|
||||
Err(e) => return Err(anyhow!("Instance {}: {}", i, e.to_string())),
|
||||
}
|
||||
@ -265,15 +266,7 @@ impl SubInstance {
|
||||
&self.ready_times,
|
||||
&self.due_times,
|
||||
)?;
|
||||
if total_distance <= self.baseline_total_distance {
|
||||
Ok(total_distance)
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"Total distance ({}) exceeds max total distance ({})",
|
||||
total_distance,
|
||||
self.baseline_total_distance
|
||||
))
|
||||
}
|
||||
Ok(total_distance)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user