Skip to content

Commit

Permalink
mpifix, figure generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alirezalm committed Oct 14, 2022
1 parent 2474aff commit 8ef31aa
Show file tree
Hide file tree
Showing 18 changed files with 55 additions and 11 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ set(CMAKE_CXX_STANDARD 17)
include_directories(DOSE)
include_directories(DOSE/include)
include_directories(ExternLibs/spdlog)
include_directories(/home/alireza/gurobi952/linux64/include)
link_directories(/home/alireza/gurobi952/linux64/lib ) #todo : must be changed
include_directories(/home/goder/gurobi/gurobi952/linux64/include)
link_directories(/home/goder/gurobi/gurobi952/linux64/lib ) #todo : must be changed
add_executable(${PROJECT_NAME}
src/scot.cpp
DOSE/include/DOSE.h
Expand Down
21 changes: 13 additions & 8 deletions scotpy/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from typing import Dict, List
import numpy as np
from matplotlib.ticker import MaxNLocator
from sklearn.datasets import make_classification

from scotpy import AlgorithmType, ProblemType, ScotModel, ScotPy, ScotSettings
Expand Down Expand Up @@ -267,7 +268,7 @@ def run(self, solver: Solvers, settings: SolverSettings):

success = self.__run_scot(scot_settings)
print(
Colors.UNDERLINE + Colors.OKBLUE + Colors.BOLD + f"{solver.name} -> Number of problem solved: {success} / {self.n_problems}" + Colors.ENDC)
Colors.UNDERLINE + Colors.OKBLUE + Colors.BOLD + f"{solver.name} -> Number of problem solved: {success} / {self.n_problems}" + Colors.ENDC)
return success

elif solver == Solvers.SCOTH:
Expand All @@ -280,7 +281,7 @@ def run(self, solver: Solvers, settings: SolverSettings):
)
success = self.__run_scot(scot_settings)
print(
Colors.UNDERLINE + Colors.OKBLUE + Colors.BOLD + f"{solver.name} -> Number of problem solved: {success} / {self.n_problems}" + Colors.ENDC)
Colors.UNDERLINE + Colors.OKBLUE + Colors.BOLD + f"{solver.name} -> Number of problem solved: {success} / {self.n_problems}" + Colors.ENDC)
return success
else:
success = self.__run_gms_solver(solver = solver, settings = settings)
Expand Down Expand Up @@ -459,17 +460,21 @@ def __visualize_results(self, results: Dict[str, List[float]]):
def plot_results_from_file(filename: str):
with open(filename, 'r') as reader:
results = json.load(reader)
fs = 10
markers = ["o", "s", "*", "h", "+", "x", "D"]
fig, ax = plt.subplots()
colors = ['midnightblue', 'mediumslateblue', 'mediumorchid', 'mediumseagreen', 'slategray', 'olive', 'red']
fig, ax = plt.subplots(figsize = (5, 4))
i = 0
for key, res in results.items():
if key != "time":
ax.step(results["time"], res, label = key, marker=markers[i])
ax.step(results["time"], res, label = key, marker = markers[i], markersize = 4, color = colors[i])
# ax.yaxis.set_major_locator(MaxNLocator(integer = True))
ax.set_yticks(range(0, 20 + 1, 2))
i += 1
ax.legend()
ax.set_xlabel("time (seconds)")
ax.set_ylabel("number of problems")
plt.legend(bbox_to_anchor = (0, 1.02, 1, 0.2), loc = "lower left",
mode = "expand", borderaxespad = 0, ncol = 4, fontsize = fs)
ax.set_xlabel("time (seconds)", fontsize = fs)
ax.set_ylabel("number of problems", fontsize = fs)
plt.grid()
figname = filename.split(".")[0] + ".pdf"
plt.savefig(f"./figs/{figname}", format = "pdf")
Expand Down
39 changes: 39 additions & 0 deletions scotpy/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from typing import List

from sklearn.datasets import make_classification


from scotpy import (AlgorithmType,
ProblemType,
ScotModel,
ScotPy,
ScotSettings
)


def main():
total_nodes = 4
models: List[ScotModel] = []

for rank in range(total_nodes):
dataset, res = make_classification(
n_samples = 500, n_features = 20, n_redundant = 0, n_repeated = 0)
scp = ScotModel(problem_name = "logistic_regression", rank = rank,
kappa = 5, ptype = ProblemType.CLASSIFICATION)
scp.set_data(dataset, res, normalized_data = True)
scp.create()
models.append(scp)

scot_settings = ScotSettings(
relative_gap = 1e-4,
time_limit = 100,
verbose = True,
algorithm = AlgorithmType.DIPOA
)

solver = ScotPy(models, scot_settings)
solver.run()


if __name__ == '__main__':
main()
Binary file added scotpy/figs/scenario_1_80.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_1_90.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_2_80.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_2_90.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_3_80.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_3_90.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_4_80.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_4_90.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_5_80.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_5_90.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_6_80.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_6_90.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_7_80.pdf
Binary file not shown.
Binary file added scotpy/figs/scenario_7_90.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion scotpy/scenario_1_90.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
3,
6,
8,
7,
8,
10,
12,
12,
Expand Down

0 comments on commit 8ef31aa

Please sign in to comment.