ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
LinearVariable.cs
Go to the documentation of this file.
2
3/// <summary>
4/// Describes one variable in a portable linear mathematical model.
5/// </summary>
6public sealed class LinearVariable
7{
8 /// <summary>Initializes a variable.</summary>
10 int id,
11 string name,
13 double lowerBound,
14 double upperBound)
15 {
16 if (id < 0)
17 {
18 throw new ArgumentOutOfRangeException(nameof(id));
19 }
20
21 if (string.IsNullOrWhiteSpace(name))
22 {
23 throw new ArgumentException(
24 "A variable name is required.",
25 nameof(name));
26 }
27
28 if (!double.IsFinite(lowerBound) ||
29 (!double.IsFinite(upperBound) &&
30 !double.IsPositiveInfinity(upperBound)))
31 {
32 throw new ArgumentOutOfRangeException(
33 nameof(lowerBound),
34 "Variable bounds must be finite, except for +infinity.");
35 }
36
37 if (lowerBound > upperBound)
38 {
39 throw new ArgumentException(
40 "The lower bound cannot exceed the upper bound.");
41 }
42
43 if (type == LinearVariableType.Binary &&
44 (lowerBound < 0.0 || upperBound > 1.0))
45 {
46 throw new ArgumentException(
47 "Binary-variable bounds must be contained in [0,1].");
48 }
49
50 Id = id;
51 Name = name.Trim();
52 Type = type;
53 LowerBound = lowerBound;
54 UpperBound = upperBound;
55 }
56
57 /// <summary>Gets the stable zero-based variable identifier.</summary>
58 public int Id { get; }
59
60 /// <summary>Gets the solver-independent variable name.</summary>
61 public string Name { get; }
62
63 /// <summary>Gets the variable domain.</summary>
64 public LinearVariableType Type { get; }
65
66 /// <summary>Gets the lower bound.</summary>
67 public double LowerBound { get; }
68
69 /// <summary>Gets the upper bound.</summary>
70 public double UpperBound { get; }
71}
LinearVariableType Type
Gets the variable domain.
string Name
Gets the solver-independent variable name.
int Id
Gets the stable zero-based variable identifier.
LinearVariable(int id, string name, LinearVariableType type, double lowerBound, double upperBound)
Initializes a variable.
LinearVariableType
Identifies the domain of a variable in a portable linear mathematical model.