-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included PuLP as a third party dependency and modified it to suite Gr…
…idCal needs
- Loading branch information
Showing
31 changed files
with
7,950 additions
and
89 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ networkx>=2.1 | |
pandas>=1.1 | ||
xlwt>=1.3.0 | ||
xlrd>=1.1.0 | ||
pulp | ||
highspy | ||
matplotlib>=2.1.1 | ||
qtconsole>=4.3.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2002-2005, Jean-Sebastien Roy | ||
Modifications Copyright (c) 2007- Stuart Anthony Mitchell | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# PuLP : Python LP Modeler | ||
# Version 1.20 | ||
|
||
# Copyright (c) 2002-2005, Jean-Sebastien Roy ([email protected]) | ||
# Modifications Copyright (c) 2007- Stuart Anthony Mitchell ([email protected]) | ||
# $Id: __init__.py 1791 2008-04-23 22:54:34Z smit023 $ | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a | ||
# copy of this software and associated documentation files (the | ||
# "Software"), to deal in the Software without restriction, including | ||
# without limitation the rights to use, copy, modify, merge, publish, | ||
# distribute, sublicense, and/or sell copies of the Software, and to | ||
# permit persons to whom the Software is furnished to do so, subject to | ||
# the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included | ||
# in all copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | ||
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
""" | ||
Module file that imports all of the pulp functions | ||
Copyright 2007- Stuart Mitchell ([email protected]) | ||
""" | ||
from .constants import VERSION | ||
|
||
from GridCalEngine.ThirdParty.pulp.pulp import * | ||
from GridCalEngine.ThirdParty.pulp.apis import * | ||
from GridCalEngine.ThirdParty.pulp.utilities import * | ||
from GridCalEngine.ThirdParty.pulp.constants import * | ||
|
||
__version__ = VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import json | ||
from GridCalEngine.ThirdParty.pulp.apis.cplex_api import * | ||
from GridCalEngine.ThirdParty.pulp.apis.gurobi_api import * | ||
from GridCalEngine.ThirdParty.pulp.apis.scip_api import * | ||
from GridCalEngine.ThirdParty.pulp.apis.xpress_api import * | ||
from GridCalEngine.ThirdParty.pulp.apis.highs_api import * | ||
from GridCalEngine.ThirdParty.pulp.apis.copt_api import * | ||
from GridCalEngine.ThirdParty.pulp.apis.core import * | ||
|
||
_all_solvers = [ | ||
CPLEX_CMD, | ||
CPLEX_PY, | ||
GUROBI, | ||
GUROBI_CMD, | ||
XPRESS, | ||
XPRESS_CMD, | ||
XPRESS_PY, | ||
SCIP_CMD, | ||
FSCIP_CMD, | ||
SCIP_PY, | ||
HiGHS, | ||
HiGHS_CMD, | ||
COPT, | ||
COPT_DLL, | ||
COPT_CMD, | ||
] | ||
|
||
# Default solver selection | ||
LpSolverDefault = HiGHS() | ||
|
||
|
||
def setConfigInformation(**keywords): | ||
""" | ||
set the data in the configuration file | ||
at the moment will only edit things in [locations] | ||
the keyword value pairs come from the keywords dictionary | ||
""" | ||
# TODO: extend if we ever add another section in the config file | ||
# read the old configuration | ||
config = Parser() | ||
config.read(config_filename) | ||
# set the new keys | ||
for key, val in keywords.items(): | ||
config.set("locations", key, val) | ||
# write the new configuration | ||
fp = open(config_filename, "w") | ||
config.write(fp) | ||
fp.close() | ||
|
||
|
||
def configSolvers(): | ||
""" | ||
Configure the path the the solvers on the command line | ||
Designed to configure the file locations of the solvers from the | ||
command line after installation | ||
""" | ||
configlist = [ | ||
(cplex_dll_path, "cplexpath", "CPLEX: "), | ||
(coinMP_path, "coinmppath", "CoinMP dll (windows only): "), | ||
] | ||
print( | ||
"Please type the full path including filename and extension \n" | ||
+ "for each solver available" | ||
) | ||
configdict = {} | ||
for default, key, msg in configlist: | ||
value = input(msg + "[" + str(default) + "]") | ||
if value: | ||
configdict[key] = value | ||
setConfigInformation(**configdict) | ||
|
||
|
||
def getSolver(solver, *args, **kwargs): | ||
""" | ||
Instantiates a solver from its name | ||
:param str solver: solver name to create | ||
:param args: additional arguments to the solver | ||
:param kwargs: additional keyword arguments to the solver | ||
:return: solver of type :py:class:`LpSolver` | ||
""" | ||
mapping = {k.name: k for k in _all_solvers} | ||
try: | ||
return mapping[solver](*args, **kwargs) | ||
except KeyError: | ||
raise PulpSolverError( | ||
"The solver {} does not exist in PuLP.\nPossible options are: \n{}".format( | ||
solver, mapping.keys() | ||
) | ||
) | ||
|
||
|
||
def getSolverFromDict(data): | ||
""" | ||
Instantiates a solver from a dictionary with its data | ||
:param dict data: a dictionary with, at least an "solver" key with the name | ||
of the solver to create | ||
:return: a solver of type :py:class:`LpSolver` | ||
:raises PulpSolverError: if the dictionary does not have the "solver" key | ||
:rtype: LpSolver | ||
""" | ||
solver = data.pop("solver", None) | ||
if solver is None: | ||
raise PulpSolverError("The json file has no solver attribute.") | ||
return getSolver(solver, **data) | ||
|
||
|
||
def getSolverFromJson(filename): | ||
""" | ||
Instantiates a solver from a json file with its data | ||
:param str filename: name of the json file to read | ||
:return: a solver of type :py:class:`LpSolver` | ||
:rtype: LpSolver | ||
""" | ||
with open(filename) as f: | ||
data = json.load(f) | ||
return getSolverFromDict(data) | ||
|
||
|
||
def listSolvers(onlyAvailable=False): | ||
""" | ||
List the names of all the existing solvers in PuLP | ||
:param bool onlyAvailable: if True, only show the available solvers | ||
:return: list of solver names | ||
:rtype: list | ||
""" | ||
result = [] | ||
for s in _all_solvers: | ||
solver = s(msg=False) | ||
if (not onlyAvailable) or solver.available(): | ||
result.append(solver.name) | ||
del solver | ||
return result |
Oops, something went wrong.