#### Topic: Specifying constraints for NLP

I'm new to optimization, and wish to specify the following constraints for my system:

`x[0]+x[1]+x[2] == 1`

and

`0<x[3]<a_constant`

Doing this:

```
def constraint1(x):
print 'calling constraint 1, value is:', x,
if 0<x[3]<1.5:
return 0
else:
return 1
def constraint2(x):
print 'calling constraint 2, value is:', x,
if x[0]+x[1]+x[2]==1:
return 0
else:
return 1
constraints = [constraint1, constraint2]
nlp = NLP(f=goalFunction, x0=[0.8,0.06,0.14, 1/60], c=constraints)
optStruct = nlp.solve('ralg')
```

doesn't work, as x[3]<0 is still passed to goalFunction. I'm sure I'm doing something fundamentally wrong here, but even after digging through the documentation and the examples, I can't figure out what. The return values of the constraint functions when the constraints are satisfied are <=0 as specified in the documentation.

Cheers,

Chinmay Kanchi

PhD student

University of Birmingham,

Using OpenOpt to determine optimal gut structures for herbivores.

*Last edited by cgkanchi (2010-09-28 17:13:39)*