[FEAT]: integer instead of float
cumttc opened this issue · 1 comments
Description
What do I need to do to make the data type of the optimisation parameter an integer instead of a float?
Take the following code as an example:
class local(Problem):
def init(self, bounds=None, minmax=min, name="local", log_to="None",dataset=None, additional=None, **kwargs):
self.name = name
self.log_to=None
self.s = kwargs.get('s', None)
self.rcv_i = kwargs.get('rcv_i', None)
self.num0 = kwargs.get('num0', 0)
self.num1 = kwargs.get('num1', 0)
super().init(bounds, minmax, **kwargs)
def obj_func(self, solution):
...................
bounds_problem = IntegerVar(lb=[lb_x, lb_y, lb_z, ], ub=[ub_x, ub_y, ub_z ])
localProblem = local(bounds=bounds_problem, minmax="min", name="local",s=s,rcv_i=rcv_i,num0=num0,num1=num1)
Additional Information
No response
@cumttc
I have written so many examples how to solve discrete problem with integer variables, permutation, binary, ....
Have you check examples folder yet?
https://github.com/thieu1995/mealpy/blob/master/examples/applications/discrete-problems/employee_rostering.py
from mealpy import IntegerVar, Problem
class LocalProblem(Problem):
def __init__(self, bounds=None, minmax="min", data=None, **kwargs):
self.data = data
super().__init__(bounds, minmax, **kwargs)
def obj_func(self, x):
s, rvc_i, num0, num1 = self.data
x_decoded = self.decode_solution(x)
x, y, z = x_decoded["my_var"] # Name here
# This is integer variable now.
# Do what you need to do here with these variables
## ....
return your_fitness_value_here
data = [s, rvc_i, num0, num1]
bounds = IntegerVar(lb=[lb_x, lb_y, lb_z, ], ub=[ub_x, ub_y, ub_z ], name="my_var") # Name here
lp = LocalProblem(bounds=bounds, minmax="min", data=data)