Skip to content

Commit

Permalink
Merge pull request #305 from jGaboardi/remove_ortools
Browse files Browse the repository at this point in the history
utilize `BaseSpOptExactSolver`
  • Loading branch information
jGaboardi authored Nov 21, 2022
2 parents 21fe3e0 + a0e8465 commit b4044bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
25 changes: 3 additions & 22 deletions spopt/BaseClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ def solve(self):


class BaseSpOptExactSolver(BaseSpOptSolver):
"""Base class for all spatial optimization model exact solvers.
Attributes
----------
spOptSolver : pywraplp.Solver
The or-tools MIP solver.
"""
"""Base class for all spatial optimization model exact solvers."""

def __init__(self, name):
"""Initialize.
Expand All @@ -29,23 +21,12 @@ def __init__(self, name):
name : str
The desired name for the model.
"""
try:
from ortools.linear_solver import pywraplp

self.spOptSolver = pywraplp.Solver(
name, pywraplp.Solver.CBC_MIXED_INTEGER_PROGRAMMING
)
except ImportError:
raise ImportError(
"ortools is a requirement for exact solvers. "
"you can install it with `pip install ortools`"
)

self.name = name

@abstractmethod
def solve(self):
"""Solve the optimization model."""
self.spOptSolver.Solve()
pass


class BaseSpOptHeuristicSolver(BaseSpOptSolver):
Expand Down
4 changes: 2 additions & 2 deletions spopt/locate/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import abstractmethod

from ..BaseClass import BaseSpOptSolver
from ..BaseClass import BaseSpOptExactSolver
from typing import TypeVar

import numpy as np
Expand All @@ -17,7 +17,7 @@
}


class LocateSolver(BaseSpOptSolver):
class LocateSolver(BaseSpOptExactSolver):
"""Base class for the ``locate`` package."""

def __init__(self, name: str, problem: pulp.LpProblem):
Expand Down

0 comments on commit b4044bb

Please sign in to comment.