MCPcopy Create free account
hub / github.com/PyVRP/PyVRP / add_client

Method add_client

pyvrp/Model.py:208–267  ·  view source on GitHub ↗

Adds a client with the given attributes to the model. Returns the created :class:`~pyvrp._pyvrp.Client` instance. Raises ------ ValueError When ``group`` is not ``None``, and the given ``group`` is not part of this model instance, or

(
        self,
        x: float,
        y: float,
        delivery: int | list[int] = [],
        pickup: int | list[int] = [],
        service_duration: int = 0,
        tw_early: int = 0,
        tw_late: int = np.iinfo(np.int64).max,
        release_time: int = 0,
        prize: int = 0,
        required: bool = True,
        group: ClientGroup | None = None,
        *,
        name: str = "",
    )

Source from the content-addressed store, hash-verified

206 return self
207
208 def add_client(
209 self,
210 x: float,
211 y: float,
212 delivery: int | list[int] = [],
213 pickup: int | list[int] = [],
214 service_duration: int = 0,
215 tw_early: int = 0,
216 tw_late: int = np.iinfo(np.int64).max,
217 release_time: int = 0,
218 prize: int = 0,
219 required: bool = True,
220 group: ClientGroup | None = None,
221 *,
222 name: str = "",
223 ) -> Client:
224 """
225 Adds a client with the given attributes to the model. Returns the
226 created :class:`~pyvrp._pyvrp.Client` instance.
227
228 Raises
229 ------
230 ValueError
231 When ``group`` is not ``None``, and the given ``group`` is not part
232 of this model instance, or when a required client is being added to
233 a mutually exclusive client group.
234 """
235 if group is None:
236 group_idx = None
237 elif (idx := _idx_by_id(group, self._groups)) is not None:
238 group_idx = idx
239 else:
240 raise ValueError("The given group is not in this model instance.")
241
242 if required and group is not None and group.mutually_exclusive:
243 # Required clients cannot be part of a mutually exclusive client
244 # group, since then there's nothing to decide about.
245 raise ValueError("Required client in mutually exclusive group.")
246
247 client = Client(
248 x=x,
249 y=y,
250 delivery=[delivery] if isinstance(delivery, int) else delivery,
251 pickup=[pickup] if isinstance(pickup, int) else pickup,
252 service_duration=service_duration,
253 tw_early=tw_early,
254 tw_late=tw_late,
255 release_time=release_time,
256 prize=prize,
257 required=required,
258 group=group_idx,
259 name=name,
260 )
261
262 if group_idx is not None:
263 client_idx = len(self._depots) + len(self._clients)
264 self._groups[group_idx].add_client(client_idx)
265

Calls 3

_idx_by_idFunction · 0.85
ClientClass · 0.85
appendMethod · 0.80