Google OR-Tools v9.9
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ConstantExpression.java
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package com.google.ortools.sat;
15
17public final class ConstantExpression implements LinearExpr {
18 private final long offset;
19
20 public ConstantExpression(long offset) {
21 this.offset = offset;
22 }
23
24 // LinearArgument interface.
25 @Override
26 public LinearExpr build() {
27 return this;
28 }
29
30 // LinearExpr interface.
31 @Override
32 public int numElements() {
33 return 0;
34 }
35
36 @Override
37 public int getVariableIndex(int index) {
38 throw new IllegalArgumentException("wrong index in LinearExpr.getVariable(): " + index);
39 }
40
41 @Override
42 public long getCoefficient(int index) {
43 throw new IllegalArgumentException("wrong index in LinearExpr.getCoefficient(): " + index);
44 }
45
46 @Override
47 public long getOffset() {
48 return offset;
49 }
50
51 @Override
52 public String toString() {
53 return String.format("%d", offset);
54 }
55}
LinearExpr build()
LinearArgument interface.