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.
1using System;
2using System.Xml.Serialization;
3
5
6/// <summary>
7/// Represents one coefficient-variable term in a linear
8/// expression.
9/// </summary>
10[Serializable]
11[XmlType(TypeName = "linearTerm")]
12public 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 {
35 variableId;
36
38 coefficient;
39
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(
85 {
86 throw new InvalidOperationException(
87 "A linear coefficient must be a finite number.");
88 }
89 }
90}
int VariableId
Gets or sets the identifier of the referenced mathematical variable.
Definition LinearTerm.cs:49
LinearTerm()
Initializes an empty linear term.
Definition LinearTerm.cs:17
double Coefficient
Gets or sets the coefficient multiplying the referenced variable.
Definition LinearTerm.cs:60
LinearTerm(int variableId, double coefficient)
Initializes a linear term.
Definition LinearTerm.cs:30
void EnsureValid()
Validates the linear term.
Definition LinearTerm.cs:72