Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.ExtLibs/HeuristicLab.SimSharp/3.3.1/SimSharp-3.3.1/Core/Resources/Events/PreemptiveRequest.cs @ 17487

Last change on this file since 17487 was 17487, checked in by abeham, 4 years ago

#3065: update Sim# to 3.3.1

File size: 1.3 KB
Line 
1#region License Information
2/*
3 * This file is part of SimSharp which is licensed under the MIT license.
4 * See the LICENSE file in the project root for more information.
5 */
6#endregion
7
8using System;
9
10namespace SimSharp {
11  public sealed class PreemptiveRequest : Request, IComparable<PreemptiveRequest>, IComparable {
12    public double Priority { get; private set; }
13    public bool Preempt { get; private set; }
14    public bool IsPreempted { get; internal set; }
15
16    public PreemptiveRequest(Simulation environment, Action<Event> callback, Action<Event> disposeCallback, double priority = 1, bool preempt = false)
17      : base(environment, callback, disposeCallback) {
18      Priority = priority;
19      Preempt = preempt;
20    }
21
22    public int CompareTo(PreemptiveRequest other) {
23      if (Priority > other.Priority) return 1;
24      else if (Priority < other.Priority) return -1;
25      if (Time > other.Time) return 1;
26      else if (Time < other.Time) return -1;
27      if (!Preempt && other.Preempt) return 1;
28      else if (Preempt && !other.Preempt) return -1;
29      return 0;
30    }
31
32    public int CompareTo(object obj) {
33      if (obj is PreemptiveRequest other) return CompareTo(other);
34      if (obj == null) return 1;
35      throw new ArgumentException("Can only compare to other objects of type PreemptiveRequest");
36    }
37  }
38}
Note: See TracBrowser for help on using the repository browser.