示例#1
0
func (l *LP) AddConstraint(row []float64,
	ct ConstraintType, rightHand float64) {

	// Pass a slice as a C array do &slice[0]
	C.add_constraint(l.ptr, (*C.double)(&row[0]),
		C.int(ct), C.double(rightHand))
}
示例#2
0
文件: lp.go 项目: gaffo/golp
// AddConstraint adds a constraint to the linear program. This (unlike the
// LPSolve C function), exects the data in the row param to start at index 0
// for the first column.
// See http://lpsolve.sourceforge.net/5.5/add_constraint.htm
func (l *LP) AddConstraint(row []float64, ct ConstraintType, rightHand float64) error {
	cRow := make([]C.double, len(row)+1)
	cRow[0] = 0.0
	for i := 0; i < len(row); i++ {
		cRow[i+1] = C.double(row[i])
	}
	C.add_constraint(l.ptr, &cRow[0], C.int(ct), C.double(rightHand))
	return nil
}