-
Notifications
You must be signed in to change notification settings - Fork 6
/
constr.go
37 lines (31 loc) · 1.12 KB
/
constr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package goop
// Constr represnts a linear constraint of the form x <= y, x >= y, or
// x == y. Constr uses a left and right hand side expressions along with a
// constraint sense (<=, >=, ==) to represent a generalized linear constraint
type Constr struct {
lhs Expr
rhs Expr
sense ConstrSense
}
// LessEq returns a constraint representing lhs <= rhs
func LessEq(lhs, rhs Expr) *Constr {
return &Constr{lhs, rhs, SenseLessThanEqual}
}
// Eq returns a constraint representing lhs == rhs
func Eq(lhs, rhs Expr) *Constr {
return &Constr{lhs, rhs, SenseEqual}
}
// GreaterEq returns a constraint representing lhs >= rhs
func GreaterEq(lhs, rhs Expr) *Constr {
return &Constr{lhs, rhs, SenseGreaterThanEqual}
}
// ConstrSense represents if the constraint x <= y, x >= y, or x == y. For easy
// integration with Gurobi, the senses have been encoding using a byte in
// the same way Gurobi encodes the constraint senses.
type ConstrSense byte
// Different constraint senses conforming to Gurobi's encoding.
const (
SenseEqual ConstrSense = '='
SenseLessThanEqual = '<'
SenseGreaterThanEqual = '>'
)