# Evolutionary.jl - positive integers

**URL:** <https://discourse.julialang.org/t/evolutionary-jl-positive-integers/53652>\
**Category:** General Usage\
**Created:** [January 20, 2021, 3:04am UTC](https://discourse.julialang.org/t/evolutionary-jl-positive-integers/53652 "2021-01-20T03:04:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheMEGuy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/themeguy/32/19862_2.png) [@TheMEGuy](https://discourse.julialang.org/u/TheMEGuy)\
**Post date:** [January 20, 2021, 3:04am UTC](https://discourse.julialang.org/t/evolutionary-jl-positive-integers/53652/1 "2021-01-20T03:04:38Z")

</div>

Hi,

is there a way to tell the optimizer, that the variables should be natural numbers?

I am currently trying to implement this using `PenaltyConstraints()`.  
Is there another way?

Thanks

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [January 20, 2021, 3:21am UTC](https://discourse.julialang.org/t/evolutionary-jl-positive-integers/53652/2 "2021-01-20T03:21:54Z")

</div>

Can you put an `abs` strategically in your model?

---

<div class="post-metadata">

**Author:** ![stephenll](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stephenll/32/28751_2.png) [@stephenll](https://discourse.julialang.org/u/stephenll)\
**Post date:** [January 20, 2021, 4:03am UTC](https://discourse.julialang.org/t/evolutionary-jl-positive-integers/53652/3 "2021-01-20T04:03:18Z")

</div>

You may have some look inspecting this example:

[https://github.com/wildart/Evolutionary.jl/blob/master/examples/mixedint.jl](https://github.com/wildart/Evolutionary.jl/blob/master/examples/mixedint.jl)

---

<div class="post-metadata">

**Author:** ![TheMEGuy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/themeguy/32/19862_2.png) [@TheMEGuy](https://discourse.julialang.org/u/TheMEGuy)\
**Post date:** [January 21, 2021, 2:01am UTC](https://discourse.julialang.org/t/evolutionary-jl-positive-integers/53652/4 "2021-01-21T02:01:42Z")

</div>

Thanks for your answers. I am still very new to Julia and programming in general and this forum is very helpful!

@Oscar_Smith:  
thanks for the suggestion! I will try it:D

@stephenll:  
I followed the example:  
I tried to implement the positive property by setting an upper and lower bound(lc and uc) and adding lc and uc to the `ConstraintBound` function, just like in the example.  
Besides, I have another important constraint that has to be met. By varying the penalty factors I am able to weigh those two constraints. Most of the time after the optimization, one of the two constraints was not fulfilled.

Is there a way to implement hard constraints, that always have to be met or should I try to tune the penalty factors? As far as I know, the PenaltyFunction method is a soft constraint.

Thanks
