I haven’t used GAMS before and am trying to increase my familiarity with GamsPy. I’ve attempted to write a simple model for practice, but I couldn’t accomplish something intuitive that I’ve done in other solvers’ APIs. I’m sharing a code snippet below. My issue is that I’m trying to create a constraint called basic_bound over the sets i and bl, but I want this constraint to be created only if the corresponding value in the csm parameter is less than 2. I couldn’t find an example on how to do this. How can I accomplish it?
container = Container()
"""Create Sets"""
i = container.addSet(name="i", records= _data.coef_matrix.columns.tolist(), description='groups')
j = container.addSet(name = "j", records= _data.coef_matrix.index.values.tolist(), description='components')
bl = container.addSet(name = "bl", records = _data.level_info['basic'], description= 'basic level components' )
il = container.addSet(name="il", records=_data.level_info['inter'], description='intermediate level components')
al = container.addSet(name="al", records=_data.level_info['adv'],description='advanced level components')
"""Create Params"""
csm = Parameter(container= container, name = 'csm', domain = [i,j], records = _data.current_state_matrix.unstack(), description = 'current state matrix')
c = container.addParameter(name = 'c', domain= [i,j], records = _data.coef_matrix.unstack(), description = 'coefficient matrix')
"""Create Variables"""
x = container.addVariable(name = 'x', type='integer', domain = [i,j], description='end state of a component' )
x.lo[i,j] == 0
x.up[i,j] == 5
"""Constraints"""
basic_bound = Equation(m, name="stock", domain=[i, bl], description="Basic Bound Constraints")
basic_bound[i,bl] = x[i, bl] <= 4 if csm[i,bl] <= 2