Hi, it is not possible to add a constraint in order to "force" a real variable to be an integer. More generally, in mixed integer programming you need to specify which variable is real and which one is integer.
When you use metaheuristics to solve some problem you usually do that in some programming language (C,C++,...). So you could add some if questions in program like this
if (int(dv)-dv==0) ....
Since equation above is rarely true, you could define some precision, like
Depending on the "metaheuristic" one can intervene in each of the underlying evolutionary algorithms to enforce an integer constraint set. For example, in a genetic algorithm or BBO one can define the problem so the only choices considered are discrete, a priori. If you are using some "interpolation" scheme (gradient based or otherwise) to generate candidate decision variable choices for the next generation, you may modify the primary code to test for integer candidate solutions and simply reject non-integer (or other non-feasible) solutions. This of course can become very costly if one of the underlying algorithm continues to generate many non-integer candidates before "finding" an integer candidate.
Alternatively you may go so far as to extend the "meta heuristic" by adding a kind of branch-and-bound logic on top of the non-integer solutions produced by your metaheuristic, to search the finite (but potentially combinatorially complex) set of integer solutions that bracket your non-integer metaheuristic result.
Then take a course on the subject of integer optimization (or combinatorial optimization, as it is also sometimes called), and apply what you have learnt; that's what most every one here at RG does (or at least I hope so). To be in a hurry to produce something will almost always yield incomplete or invalid results. I also suggest that you throw away the use of metaheuristics altogether, and instead learn the subject of combinatorial/integer optimization, which is the only one that will guarantee that you find an optimum - something that a metaheuristic will NOT.
There is basically no other way to address your problem, as by studying carefully integer programming and combinatorial programming. I agree with Michael Patrikkson, that the use of so-called tricks as rounding off might lead to wrong results. In general I find, that too many people ask questions before having done their homework, by studying the relevant literature.!
GENO does that easily. The program is described in detail in the User's Manual which is available on-demand from Amazon.com. Here is a brief extract from the preface:
"By mere choice of a few parameters at the ‘problem set-up’ stage of the solution process, GENO may be set to solve specific classes of problems such as nonlinear equation systems, static optimization problems, mixed-integer problems, or two-point boundary value dynamic optimization problems; similarly, it may be set to generate real or integer-valued solutions, or a mixture of the two as required . . ."
In case you like to use a black box, be my friend, and use for instance GENO, but then, it is not a metaheuristic, it is a collection of algorithms. My advise still is, to invest some time in studying the relevant literature in the area of operations research, but I admit, that there are faster ways to become rich!
Correction: GENO is not "a collection of algorithms"; it is actually a single (genetic) algorithm that may be instantiated to address a particular problem belonging to a fairly wide class of problem-types; the said class includes, inter alia, 'mixed-variable optimization problems' and 'nonlinear equation systems'
Point taken, but, it is not a metaheuristic, and , my main point " devote time and energy to operations research" seems to be overheard, and that is a pity, but fits into my perception of the degradation of university studies!