ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
LinearConstraint.cs
Go to the documentation of this file.
2
3/// <summary>
4/// Describes one portable linear constraint.
5/// </summary>
6public sealed class LinearConstraint
7{
8 private readonly LinearTerm[] _terms;
9
10 /// <summary>Initializes a linear constraint.</summary>
12 string name,
13 IEnumerable<LinearTerm> terms,
15 double rightHandSide)
16 {
17 if (string.IsNullOrWhiteSpace(name))
18 {
19 throw new ArgumentException(
20 "A constraint name is required.",
21 nameof(name));
22 }
23
24 ArgumentNullException.ThrowIfNull(terms);
25
26 if (!double.IsFinite(rightHandSide))
27 {
28 throw new ArgumentOutOfRangeException(
29 nameof(rightHandSide),
30 "The right-hand side must be finite.");
31 }
32
33 _terms = terms
34 .Where(
35 static term =>
36 term.Coefficient != 0.0)
37 .ToArray();
38
39 if (_terms
40 .GroupBy(
41 static term =>
42 term.VariableId)
43 .Any(
44 static group =>
45 group.Count() > 1))
46 {
47 throw new ArgumentException(
48 "A constraint cannot contain duplicate variable identifiers.",
49 nameof(terms));
50 }
51
52 Name = name.Trim();
53 Sense = sense;
54 RightHandSide = rightHandSide;
55 }
56
57 /// <summary>Gets the constraint name.</summary>
58 public string Name { get; }
59
60 /// <summary>Gets the nonzero terms.</summary>
61 public IReadOnlyList<LinearTerm> Terms => _terms;
62
63 /// <summary>Gets the constraint sense.</summary>
65
66 /// <summary>Gets the right-hand side.</summary>
67 public double RightHandSide { get; }
68}
LinearConstraintSense Sense
Gets the constraint sense.
IReadOnlyList< LinearTerm > Terms
Gets the nonzero terms.
LinearConstraint(string name, IEnumerable< LinearTerm > terms, LinearConstraintSense sense, double rightHandSide)
Initializes a linear constraint.
LinearConstraintSense
Identifies the sense of a portable linear constraint.
Stores one coefficient of a portable linear expression.
Definition LinearTerm.cs:7