我有定义的一个问题,这将最大限度地降低成本的运行一个水泵。 这被定义为目的的问题。
cost_cp = cp.sum(cp.multiply(cost_,selection))
objective = cp.Minimize(cost_cp)
该问题定义为:
problem = cp.Problem(objective, constraints)
我跑的计算使用的 cp.multiply
和 cp.vec
为计算差值在储卷,它提供了我的答案,我希望与正确的差异。
flow_in = cp.vec(cp.multiply(input_flow_, flow_in_minutes))
flow_out = cp.vec(flow_out_)
flow_diff = flow_in - flow_out
问题出现时我的计算累积求和使用 cp.cumsum
. 它的工作和计算正确,但是当我想添加的限制围绕这是我提供的 DCPError
我不确定我要去的错误在这样计算,因为它曾在以前没有问题,对我来说。
约束我希望定义是:
volume_constraint = volume_cp >= 300000
min_level_constraint = res_level >= min_level
max_level_constraint = res_level <= max_level
constraints = [assignment_constraint, volume_constraint, min_level_constraint, max_level_constraint]
的 volume_constraint
完美的作品。 问题是有的 min_level_constraint
和 max_level_constraint
.
我尝试解决方案的使用
problem.solve(solver=cp.CPLEX, verbose=False)
一种回溯在我提供的是:
DCPError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_14560/1602474026.py in <module>
33
34 # Problem solve
---> 35 problem.solve(solver=cp.CPLEX, verbose=False)
~\AppData\Local\Programs\Python\Python38\lib\site-packages\cvxpy\problems\problem.py in solve(self, *args, **kwargs)
457 else:
458 solve_func = Problem._solve
--> 459 return solve_func(self, *args, **kwargs)
460
461 @classmethod
~\AppData\Local\Programs\Python\Python38\lib\site-packages\cvxpy\problems\problem.py in _solve(self, solver, warm_start, verbose, gp, qcp, requires_grad, enforce_dpp, **kwargs)
936 return self.value
937
--> 938 data, solving_chain, inverse_data = self.get_problem_data(
939 solver, gp, enforce_dpp, verbose)
940
~\AppData\Local\Programs\Python\Python38\lib\site-packages\cvxpy\problems\problem.py in get_problem_data(self, solver, gp, enforce_dpp, verbose)
563 if key != self._cache.key:
564 self._cache.invalidate()
--> 565 solving_chain = self._construct_chain(
566 solver=solver, gp=gp, enforce_dpp=enforce_dpp)
567 self._cache.key = key
~\AppData\Local\Programs\Python\Python38\lib\site-packages\cvxpy\problems\problem.py in _construct_chain(self, solver, gp, enforce_dpp)
789 candidate_solvers = self._find_candidate_solvers(solver=solver, gp=gp)
790 self._sort_candidate_solvers(candidate_solvers)
--> 791 return construct_solving_chain(self, candidate_solvers, gp=gp,
792 enforce_dpp=enforce_dpp)
793
~\AppData\Local\Programs\Python\Python38\lib\site-packages\cvxpy\reductions\solvers\solving_chain.py in construct_solving_chain(problem, candidates, gp, enforce_dpp)
153 if len(problem.variables()) == 0:
154 return SolvingChain(reductions=[ConstantSolver()])
--> 155 reductions = _reductions_for_problem_class(problem, candidates, gp)
156
157 dpp_context = 'dcp' if not gp else 'dgp'
~\AppData\Local\Programs\Python\Python38\lib\site-packages\cvxpy\reductions\solvers\solving_chain.py in _reductions_for_problem_class(problem, candidates, gp)
89 append += ("\nHowever, the problem does follow DQCP rules. "
90 "Consider calling solve() with `qcp=True`.")
---> 91 raise DCPError(
92 "Problem does not follow DCP rules. Specifically:\n" + append)
93 elif gp and not problem.is_dgp():
我已经看了看四周的文件CVXPY和堆溢出,但我什么也没有发现在这工作我的问题。 我感到困惑,因为它已经为我的过去。