MCPcopy Index your code
hub / github.com/PyVRP/PyVRP / from_data

Method from_data

pyvrp/Model.py:161–206  ·  view source on GitHub ↗

Constructs a model instance from the given data. .. tip:: Only use this method if you intend to change the data using the model interface. If you only want to solve the given data instance, it is faster to directly call :meth:`~pyvrp.solve.solve`.

(cls, data: ProblemData)

Source from the content-addressed store, hash-verified

159
160 @classmethod
161 def from_data(cls, data: ProblemData) -> "Model":
162 """
163 Constructs a model instance from the given data.
164
165 .. tip::
166 Only use this method if you intend to change the data using the
167 model interface. If you only want to solve the given data instance,
168 it is faster to directly call :meth:`~pyvrp.solve.solve`.
169
170 Parameters
171 ----------
172 data
173 Problem data to feed into the model.
174
175 Returns
176 -------
177 Model
178 A model instance representing the given data.
179 """
180 depots = data.depots()
181 clients = data.clients()
182 locs = depots + clients
183
184 profiles = [Profile() for _ in range(data.num_profiles)]
185 for idx, profile in enumerate(profiles):
186 distances = data.distance_matrix(profile=idx)
187 durations = data.duration_matrix(profile=idx)
188 profile.edges = [
189 Edge(
190 frm=locs[frm],
191 to=locs[to],
192 distance=distances[frm, to],
193 duration=durations[frm, to],
194 )
195 for frm in range(data.num_locations)
196 for to in range(data.num_locations)
197 ]
198
199 self = Model()
200 self._clients = clients
201 self._depots = depots
202 self._groups = data.groups()
203 self._profiles = profiles
204 self._vehicle_types = data.vehicle_types()
205
206 return self
207
208 def add_client(
209 self,

Calls 7

ProfileClass · 0.85
EdgeClass · 0.85
ModelClass · 0.85
depotsMethod · 0.80
clientsMethod · 0.80
groupsMethod · 0.80
vehicle_typesMethod · 0.80