LotSizingDataModel.Solver
2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
LinearTerm.cs
Go to the documentation of this file.
1
using
System;
2
using
System.Xml.Serialization;
3
4
namespace
LotSizingDataModel.Solver.Modeling
;
5
6
/// <summary>
7
/// Represents one coefficient-variable term in a linear
8
/// expression.
9
/// </summary>
10
[Serializable]
11
[XmlType(TypeName =
"linearTerm"
)]
12
public
sealed
class
LinearTerm
13
{
14
/// <summary>
15
/// Initializes an empty linear term.
16
/// </summary>
17
public
LinearTerm
()
18
{
19
}
20
21
/// <summary>
22
/// Initializes a linear term.
23
/// </summary>
24
/// <param name="variableId">
25
/// Identifier of the referenced mathematical variable.
26
/// </param>
27
/// <param name="coefficient">
28
/// Linear coefficient.
29
/// </param>
30
public
LinearTerm
(
31
int
variableId,
32
double
coefficient)
33
{
34
VariableId
=
35
variableId;
36
37
Coefficient
=
38
coefficient;
39
40
EnsureValid
();
41
}
42
43
/// <summary>
44
/// Gets or sets the identifier of the referenced
45
/// mathematical variable.
46
/// </summary>
47
[XmlAttribute(
"variableId"
)]
48
public
int
VariableId
49
{
50
get
;
51
set
;
52
}
53
54
/// <summary>
55
/// Gets or sets the coefficient multiplying the referenced
56
/// variable.
57
/// </summary>
58
[XmlAttribute(
"coefficient"
)]
59
public
double
Coefficient
60
{
61
get
;
62
set
;
63
}
64
65
/// <summary>
66
/// Validates the linear term.
67
/// </summary>
68
/// <exception cref="InvalidOperationException">
69
/// Thrown when the variable identifier or coefficient is
70
/// invalid.
71
/// </exception>
72
public
void
EnsureValid
()
73
{
74
if
(
VariableId
<= 0)
75
{
76
throw
new
InvalidOperationException(
77
"A linear term must reference a strictly "
+
78
"positive variable identifier."
);
79
}
80
81
if
(
double
.IsNaN(
82
Coefficient
) ||
83
double
.IsInfinity(
84
Coefficient
))
85
{
86
throw
new
InvalidOperationException(
87
"A linear coefficient must be a finite number."
);
88
}
89
}
90
}
LotSizingDataModel.Solver.Modeling.LinearTerm.VariableId
int VariableId
Gets or sets the identifier of the referenced mathematical variable.
Definition
LinearTerm.cs:49
LotSizingDataModel.Solver.Modeling.LinearTerm.LinearTerm
LinearTerm()
Initializes an empty linear term.
Definition
LinearTerm.cs:17
LotSizingDataModel.Solver.Modeling.LinearTerm.Coefficient
double Coefficient
Gets or sets the coefficient multiplying the referenced variable.
Definition
LinearTerm.cs:60
LotSizingDataModel.Solver.Modeling.LinearTerm.LinearTerm
LinearTerm(int variableId, double coefficient)
Initializes a linear term.
Definition
LinearTerm.cs:30
LotSizingDataModel.Solver.Modeling.LinearTerm.EnsureValid
void EnsureValid()
Validates the linear term.
Definition
LinearTerm.cs:72
LotSizingDataModel.Solver.Modeling
Definition
LinearConstraint.cs:4
LotSizingDataModel.Solver
Modeling
LinearTerm.cs
Generated by
1.17.0