Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Update scenario solver parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlan committed Sep 22, 2023
1 parent 46cdc49 commit 9d464ff
Show file tree
Hide file tree
Showing 2 changed files with 1,322 additions and 23 deletions.
32 changes: 9 additions & 23 deletions ddwp/static_solvers/scenario_solver.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import warnings

from ddwp.VrpInstance import VrpInstance
from pyvrp import (
GeneticAlgorithm,
GeneticAlgorithmParams,
PenaltyManager,
PenaltyParams,
Population,
PopulationParams,
RandomNumberGenerator,
Expand All @@ -16,18 +15,16 @@
from pyvrp.exceptions import EmptySolutionWarning
from pyvrp.search import (
Exchange10,
Exchange11,
LocalSearch,
NeighbourhoodParams,
RelocateStar,
SwapRoutes,
SwapStar,
TwoOpt,
compute_neighbours,
)
from pyvrp.stop import MaxRuntime

from ddwp.VrpInstance import VrpInstance

from .instance2data import instance2data

warnings.filterwarnings("ignore", category=EmptySolutionWarning)
Expand Down Expand Up @@ -59,42 +56,31 @@ def scenario_solver(
AssertionError
If no feasible solution is found.
"""
gen_params = GeneticAlgorithmParams(repair_probability=0.5)
pen_params = PenaltyParams(
init_time_warp_penalty=14,
repair_booster=12,
num_registrations_between_penalty_updates=20,
penalty_increase=2,
penalty_decrease=0.34,
target_feasible=0.19,
)
pop_params = PopulationParams(min_pop_size=5, generation_size=15)
nb_params = NeighbourhoodParams(
weight_wait_time=5, weight_time_warp=18, nb_granular=25
pop_params = PopulationParams(
min_pop_size=5, generation_size=3, nb_elite=2, nb_close=2
)
nb_params = NeighbourhoodParams(nb_granular=20)

data = instance2data(instance)
rng = RandomNumberGenerator(seed=seed)
pen_manager = PenaltyManager(pen_params)
pen_manager = PenaltyManager()
pop = Population(bpd, params=pop_params)

neighbours = compute_neighbours(data, nb_params)
ls = LocalSearch(data, rng, neighbours)

node_ops = [Exchange10, Exchange11, TwoOpt]
node_ops = [Exchange10, TwoOpt]
for node_op in node_ops:
ls.add_node_operator(node_op(data))

route_ops = [SwapStar, SwapRoutes]
route_ops = [RelocateStar, SwapStar, SwapRoutes]
for route_op in route_ops:
ls.add_route_operator(route_op(data))

init = [
Solution.make_random(data, rng) for _ in range(pop_params.min_pop_size)
]
algo = GeneticAlgorithm(
data, pen_manager, rng, pop, ls, srex, init, gen_params
)
algo = GeneticAlgorithm(data, pen_manager, rng, pop, ls, srex, init)
res = algo.run(MaxRuntime(time_limit))

assert res.best.is_feasible(), "No feasible solution found."
Expand Down
Loading

0 comments on commit 9d464ff

Please sign in to comment.