ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
LinearObjective.cs
Go to the documentation of this file.
2
3/// <summary>
4/// Describes the minimization objective of a portable linear model.
5/// </summary>
6public sealed class LinearObjective
7{
8 private readonly LinearTerm[] _terms;
9
10 /// <summary>Initializes a minimization objective.</summary>
12 IEnumerable<LinearTerm> terms,
13 double constant = 0.0)
14 {
15 ArgumentNullException.ThrowIfNull(terms);
16
17 if (!double.IsFinite(constant))
18 {
19 throw new ArgumentOutOfRangeException(
20 nameof(constant));
21 }
22
23 _terms = terms
24 .Where(
25 static term =>
26 term.Coefficient != 0.0)
27 .ToArray();
28
29 if (_terms
30 .GroupBy(
31 static term =>
32 term.VariableId)
33 .Any(
34 static group =>
35 group.Count() > 1))
36 {
37 throw new ArgumentException(
38 "The objective cannot contain duplicate variable identifiers.",
39 nameof(terms));
40 }
41
42 Constant = constant;
43 }
44
45 /// <summary>Gets nonzero objective terms.</summary>
46 public IReadOnlyList<LinearTerm> Terms => _terms;
47
48 /// <summary>Gets the objective constant.</summary>
49 public double Constant { get; }
50}
LinearObjective(IEnumerable< LinearTerm > terms, double constant=0.0)
Initializes a minimization objective.
IReadOnlyList< LinearTerm > Terms
Gets nonzero objective terms.
double Constant
Gets the objective constant.
Stores one coefficient of a portable linear expression.
Definition LinearTerm.cs:7