Originally posted by: JPRyan
I'm getting a weird error "CPLEX Error 5012: Q is not symmetric." adding absolute values to cost functions when building a toy (two variable) problem in DocPlex. I attached the python file for the full script.
My full cost function has three parts c_costs, t_costs, and f_costs and one constraint:
mdl = AdvModel()
current = Series([0.6, 0.4], ['a1', 'a2'])
var = mdl.continuous_var_list(len(current), lb=0, ub=1, name='Target')
target = Series(var, current.index, name='Target')
# Cost Code Below
mdl.minimize(c_costs + t_costs + f_costs)
mdl.add_constraint(mdl.sum(target) == 1)
Where c_costs and f_costs are both quadratic:
c_costs = r * mdl.quad_matrix_sum(covar, target)
f_costs = h * mdl.sumsq(target - optimal)
and r&h are constants greater than zero.
Interestingly, minimizing over just these quadratic costs works fine as covar is symmetric so Q must be symmetric
mdl.minimize(c_costs + f_costs)
mdl.solve()
When I add the t_costs with absolute values (maybe this could be written better but there is no vector version of abs() in CPlex??) it fails with the error "CPLEX Error 5012: Q is not symmetric."
abs_series = Series([mdl.abs(target[i] - current[i]) for i in current.index], current.index)
t_costs = linear_costs.dot(abs_series)
mdl.minimize(c_costs + t_costs + f_costs)
The crazy thing is these costs are _linear_ so they shouldn't affect the Q matrix!
Even weirder... both of the following work combined with the absolute value term! But the combination of all three fails!!
mdl.minimize( t_costs + f_costs)
mdl.solve()
mdl.minimize( c_costs + t_costs )
mdl.solve()
#CPLEXOptimizers#DecisionOptimization