@@ -61,7 +61,14 @@ pub trait Heuristic<TS, S, A, C, DC>
61
61
where
62
62
TS : TransitionSystem < S , A , C , DC > ,
63
63
S : Hash + Eq + Clone ,
64
- C : Eq + PartialOrd + Ord + Add < DC , Output = C > + Copy + Default + LimitValues ,
64
+ C : Eq
65
+ + PartialOrd
66
+ + Ord
67
+ + Add < DC , Output = C >
68
+ + Sub < C , Output = DC >
69
+ + Copy
70
+ + Default
71
+ + LimitValues ,
65
72
{
66
73
/// Returns the heuristic value for the given state,
67
74
/// or None if the goal state is not reachable from that state.
@@ -73,7 +80,14 @@ pub trait MinimalHeuristic<TS, S, A, C, DC>
73
80
where
74
81
TS : TransitionSystem < S , A , C , DC > ,
75
82
S : State + Hash + Eq + Clone ,
76
- C : Eq + PartialOrd + Ord + Add < DC , Output = C > + Copy + Default + LimitValues ,
83
+ C : Eq
84
+ + PartialOrd
85
+ + Ord
86
+ + Add < DC , Output = C >
87
+ + Sub < C , Output = DC >
88
+ + Copy
89
+ + Default
90
+ + LimitValues ,
77
91
{
78
92
fn build ( transition_system : Arc < TS > , task : Arc < Task < S , C > > ) -> Self ;
79
93
}
@@ -215,20 +229,20 @@ pub enum ConflictType {
215
229
#[ derive( Debug ) ]
216
230
pub struct Conflict < S , A , C , DC >
217
231
where
218
- C : Ord + LimitValues ,
232
+ C : Ord + LimitValues + Sub < C , Output = DC > + Copy ,
219
233
DC : Ord + Default ,
220
234
{
221
- pub moves : A2 < Move < S , A , C > > ,
235
+ pub moves : A2 < Move < S , A , C , DC > > ,
222
236
pub type_ : ConflictType ,
223
237
pub overcost : DC ,
224
238
}
225
239
226
240
impl < S , A , C , DC > Conflict < S , A , C , DC >
227
241
where
228
- C : Ord + LimitValues ,
242
+ C : Ord + LimitValues + Sub < C , Output = DC > + Copy ,
229
243
DC : Ord + Default ,
230
244
{
231
- pub fn new ( moves : A2 < Move < S , A , C > > ) -> Self {
245
+ pub fn new ( moves : A2 < Move < S , A , C , DC > > ) -> Self {
232
246
Self {
233
247
moves,
234
248
type_ : ConflictType :: NonCardinal ,
@@ -239,7 +253,7 @@ where
239
253
240
254
impl < S , A , C , DC > PartialEq for Conflict < S , A , C , DC >
241
255
where
242
- C : Ord + Copy + LimitValues ,
256
+ C : Ord + Copy + LimitValues + Sub < C , Output = DC > ,
243
257
DC : Ord + Default ,
244
258
{
245
259
fn eq ( & self , other : & Self ) -> bool {
@@ -257,14 +271,14 @@ where
257
271
258
272
impl < S , A , C , DC > Eq for Conflict < S , A , C , DC >
259
273
where
260
- C : Ord + Copy + LimitValues ,
274
+ C : Ord + Copy + LimitValues + Sub < C , Output = DC > ,
261
275
DC : Ord + Default ,
262
276
{
263
277
}
264
278
265
279
impl < S , A , C , DC > PartialOrd for Conflict < S , A , C , DC >
266
280
where
267
- C : Ord + Copy + LimitValues ,
281
+ C : Ord + Copy + LimitValues + Sub < C , Output = DC > ,
268
282
DC : Ord + Default ,
269
283
{
270
284
fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
@@ -274,7 +288,7 @@ where
274
288
275
289
impl < S , A , C , DC > Ord for Conflict < S , A , C , DC >
276
290
where
277
- C : Ord + Copy + LimitValues ,
291
+ C : Ord + Copy + LimitValues + Sub < C , Output = DC > ,
278
292
DC : Ord + Default ,
279
293
{
280
294
fn cmp ( & self , other : & Self ) -> Ordering {
@@ -306,26 +320,26 @@ pub trait LimitValues {
306
320
307
321
/// Defines a time interval (start <= end).
308
322
#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
309
- pub struct Interval < C >
323
+ pub struct Interval < C , DC >
310
324
where
311
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues ,
325
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
312
326
{
313
327
pub start : C ,
314
328
pub end : C ,
315
329
}
316
330
317
- impl < C > Default for Interval < C >
331
+ impl < C , DC > Default for Interval < C , DC >
318
332
where
319
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues ,
333
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
320
334
{
321
335
fn default ( ) -> Self {
322
336
Self :: new ( C :: min_value ( ) , C :: max_value ( ) )
323
337
}
324
338
}
325
339
326
- impl < C > Interval < C >
340
+ impl < C , DC > Interval < C , DC >
327
341
where
328
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues ,
342
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
329
343
{
330
344
pub fn new ( start : C , end : C ) -> Self {
331
345
Self { start, end }
@@ -338,6 +352,10 @@ where
338
352
pub fn contains ( & self , other : & Self ) -> bool {
339
353
self . start <= other. start && other. end <= self . end
340
354
}
355
+
356
+ pub fn length ( & self ) -> DC {
357
+ self . end - self . start
358
+ }
341
359
}
342
360
343
361
/// The types of constraints that can be imposed on agents in a search algorithm.
@@ -351,22 +369,24 @@ pub enum ConstraintType {
351
369
352
370
/// Defines a constraint that can be imposed on a given agent in a search algorithm.
353
371
#[ derive( Debug , Clone ) ]
354
- pub struct Constraint < S , C >
372
+ pub struct Constraint < S , C , DC >
355
373
where
356
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues ,
374
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
375
+ DC : PartialEq + Eq + PartialOrd + Ord ,
357
376
{
358
377
pub agent : usize ,
359
378
pub state : S ,
360
379
pub next : Option < S > ,
361
- pub interval : Interval < C > ,
380
+ pub interval : Interval < C , DC > ,
362
381
pub type_ : ConstraintType ,
363
382
}
364
383
365
- impl < S , C > Constraint < S , C >
384
+ impl < S , C , DC > Constraint < S , C , DC >
366
385
where
367
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues ,
386
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
387
+ DC : PartialEq + Eq + PartialOrd + Ord ,
368
388
{
369
- pub fn new_state_constraint ( agent : usize , state : S , interval : Interval < C > ) -> Self {
389
+ pub fn new_state_constraint ( agent : usize , state : S , interval : Interval < C , DC > ) -> Self {
370
390
Self {
371
391
agent,
372
392
state,
@@ -375,7 +395,12 @@ where
375
395
type_ : ConstraintType :: State ,
376
396
}
377
397
}
378
- pub fn new_action_constraint ( agent : usize , state : S , next : S , interval : Interval < C > ) -> Self {
398
+ pub fn new_action_constraint (
399
+ agent : usize ,
400
+ state : S ,
401
+ next : S ,
402
+ interval : Interval < C , DC > ,
403
+ ) -> Self {
379
404
Self {
380
405
agent,
381
406
state,
@@ -386,29 +411,37 @@ where
386
411
}
387
412
}
388
413
389
- impl < S , C > PartialEq for Constraint < S , C >
414
+ impl < S , C , DC > PartialEq for Constraint < S , C , DC >
390
415
where
391
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues ,
416
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
417
+ DC : PartialEq + Eq + PartialOrd + Ord ,
392
418
{
393
419
fn eq ( & self , other : & Self ) -> bool {
394
420
self . interval == other. interval
395
421
}
396
422
}
397
423
398
- impl < S , C > Eq for Constraint < S , C > where C : PartialEq + Eq + PartialOrd + Ord + LimitValues { }
424
+ impl < S , C , DC > Eq for Constraint < S , C , DC >
425
+ where
426
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
427
+ DC : PartialEq + Eq + PartialOrd + Ord ,
428
+ {
429
+ }
399
430
400
- impl < S , C > PartialOrd for Constraint < S , C >
431
+ impl < S , C , DC > PartialOrd for Constraint < S , C , DC >
401
432
where
402
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues ,
433
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
434
+ DC : PartialEq + Eq + PartialOrd + Ord ,
403
435
{
404
436
fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
405
437
Some ( self . cmp ( other) )
406
438
}
407
439
}
408
440
409
- impl < S , C > Ord for Constraint < S , C >
441
+ impl < S , C , DC > Ord for Constraint < S , C , DC >
410
442
where
411
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues ,
443
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Sub < C , Output = DC > + Copy ,
444
+ DC : PartialEq + Eq + PartialOrd + Ord ,
412
445
{
413
446
fn cmp ( & self , other : & Self ) -> Ordering {
414
447
self . interval . cmp ( & other. interval )
@@ -417,19 +450,21 @@ where
417
450
418
451
/// Set of constraints that can be imposed on agents in a search algorithm.
419
452
#[ derive( Debug ) ]
420
- pub struct ConstraintSet < S , C >
453
+ pub struct ConstraintSet < S , C , DC >
421
454
where
422
455
S : State + Eq + Hash + Clone ,
423
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Copy ,
456
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Copy + Sub < C , Output = DC > ,
457
+ DC : PartialEq + Eq + PartialOrd + Ord + Copy ,
424
458
{
425
- pub state_constraints : FxHashMap < S , Vec < Constraint < S , C > > > ,
426
- pub action_constraints : FxHashMap < ( S , S ) , Vec < Constraint < S , C > > > ,
459
+ pub state_constraints : FxHashMap < S , Vec < Constraint < S , C , DC > > > ,
460
+ pub action_constraints : FxHashMap < ( S , S ) , Vec < Constraint < S , C , DC > > > ,
427
461
}
428
462
429
- impl < S , C > Default for ConstraintSet < S , C >
463
+ impl < S , C , DC > Default for ConstraintSet < S , C , DC >
430
464
where
431
465
S : State + Eq + Hash + Clone ,
432
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Copy ,
466
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Copy + Sub < C , Output = DC > ,
467
+ DC : PartialEq + Eq + PartialOrd + Ord + Copy ,
433
468
{
434
469
fn default ( ) -> Self {
435
470
Self {
@@ -439,12 +474,13 @@ where
439
474
}
440
475
}
441
476
442
- impl < S , C > ConstraintSet < S , C >
477
+ impl < S , C , DC > ConstraintSet < S , C , DC >
443
478
where
444
479
S : State + Eq + Hash + Clone ,
445
- C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Copy ,
480
+ C : PartialEq + Eq + PartialOrd + Ord + LimitValues + Copy + Sub < C , Output = DC > ,
481
+ DC : PartialEq + Eq + PartialOrd + Ord + Copy ,
446
482
{
447
- pub fn add ( & mut self , constraint : & Arc < Constraint < S , C > > ) {
483
+ pub fn add ( & mut self , constraint : & Arc < Constraint < S , C , DC > > ) {
448
484
match constraint. type_ {
449
485
ConstraintType :: State => {
450
486
self . state_constraints
@@ -464,11 +500,11 @@ where
464
500
}
465
501
}
466
502
467
- pub fn get_state_constraints ( & self , state : & S ) -> Option < & Vec < Constraint < S , C > > > {
503
+ pub fn get_state_constraints ( & self , state : & S ) -> Option < & Vec < Constraint < S , C , DC > > > {
468
504
self . state_constraints . get ( state)
469
505
}
470
506
471
- pub fn get_action_constraints ( & self , from : & S , to : & S ) -> Option < & Vec < Constraint < S , C > > > {
507
+ pub fn get_action_constraints ( & self , from : & S , to : & S ) -> Option < & Vec < Constraint < S , C , DC > > > {
472
508
self . action_constraints . get ( & ( from. clone ( ) , to. clone ( ) ) )
473
509
}
474
510
@@ -525,4 +561,4 @@ where
525
561
}
526
562
}
527
563
528
- pub type LandmarkSet < S , C > = Vec < Arc < Constraint < S , C > > > ;
564
+ pub type LandmarkSet < S , C , DC > = Vec < Arc < Constraint < S , C , DC > > > ;
0 commit comments