Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dran-Z committed Dec 9, 2022
1 parent d9bb223 commit b511b9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions qiskit_optimization/algorithms/scipy_milp_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_compatibility_msg(self, problem: QuadraticProgram) -> str:
def _generate_problem(self, problem: QuadraticProgram):

from scipy.optimize import LinearConstraint, Bounds
from scipy.sparse import csc_matrix
from scipy.sparse import lil_matrix

## Obtain sense of objective function (+1 for minimization and -1 for maximization)
sense = problem.objective.sense.value
Expand All @@ -88,7 +88,7 @@ def _generate_problem(self, problem: QuadraticProgram):
objective = problem.objective.linear.to_array() * sense

## Initialize constraints matrix
constraints_matrix = csc_matrix(len(problem.linear_constraints), len(problem.variables))
constraints_matrix = lil_matrix((len(problem.linear_constraints), len(problem.variables)))

## Initialize constraint value
left_constraint = np.array([])
Expand Down Expand Up @@ -144,12 +144,19 @@ def solve(self, problem: QuadraticProgram) -> OptimizationResult:
c=objective, integrality=integrality, bounds=bounds, constraints=constraints
)

opt_x = []
for i, ele in enumerate(opt_result.x):
if integrality[i]:
opt_x.append(round(ele))
else:
opt_x.append(ele)

# create results
result = OptimizationResult(
x=opt_result.x,
x=opt_x,
fval=opt_result.fun * sense,
variables=problem.variables,
status=opt_result.status,
status=self._get_feasibility_status(problem, opt_x),
raw_results=opt_result,
)

Expand Down
2 changes: 1 addition & 1 deletion qiskit_optimization/optionals.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

HAS_SCIPY_MILP = LazyImportTester(
{
"scipy.optimize": ("Milp",),
"scipy.optimize": ("milp",),
},
name="Scipy",
install="pip install 'qiskit-optimization[scipy]'",
Expand Down

0 comments on commit b511b9b

Please sign in to comment.