From 469ce771038d084f8c9996c3774e5930af85707b Mon Sep 17 00:00:00 2001 From: Martin Lackner Date: Tue, 30 Apr 2024 11:43:00 +0200 Subject: [PATCH] fix write_profile_to_preflib_cat_file --- abcvoting/fileio.py | 7 ++++--- examples/preflib-files/new_example.cat | 2 +- tests/data/test5.cat | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/abcvoting/fileio.py b/abcvoting/fileio.py index 47d9093..1d33dbe 100644 --- a/abcvoting/fileio.py +++ b/abcvoting/fileio.py @@ -202,7 +202,7 @@ def read_preflib_files_from_dir(dir_name, top_ranks=None, setsize=None): return profiles -def write_profile_to_preflib_cat_file(filename, profile): +def write_profile_to_preflib_cat_file(filepath, profile): """ Write a profile to a Preflib category file (.cat). @@ -219,9 +219,10 @@ def write_profile_to_preflib_cat_file(filename, profile): None """ preflib_inst = preflib.CategoricalInstance() + preflib_inst.data_type = "cat" preflib_inst.num_categories = 2 preflib_inst.categories_name = {"1": "Approved", "2": "Not approved"} - preflib_inst.file_name = filename + preflib_inst.file_name = os.path.basename(filepath) preflib_inst.num_alternatives = profile.num_cand for cand in profile.candidates: preflib_inst.alternatives_name[cand + 1] = profile.cand_names[cand] @@ -241,7 +242,7 @@ def write_profile_to_preflib_cat_file(filename, profile): else: preflib_inst.multiplicity[pref] += multiplicity preflib_inst.recompute_cardinality_param() - preflib_inst.write(filename) + preflib_inst.write(filepath) def _yaml_flow_style_list(x): diff --git a/examples/preflib-files/new_example.cat b/examples/preflib-files/new_example.cat index d41ccc7..1abb2e2 100644 --- a/examples/preflib-files/new_example.cat +++ b/examples/preflib-files/new_example.cat @@ -1,4 +1,4 @@ -# FILE NAME: C:\Users\reysi\PycharmProjects\abcvoting\examples\preflib-files/new_example.cat +# FILE NAME: new_example.cat # TITLE: # DESCRIPTION: # DATA TYPE: cat diff --git a/tests/data/test5.cat b/tests/data/test5.cat index 4a82fce..135d23d 100644 --- a/tests/data/test5.cat +++ b/tests/data/test5.cat @@ -1,4 +1,4 @@ -# FILE NAME: C:\Users\reysi\PycharmProjects\abcvoting\tests/data/test5.cat +# FILE NAME: test5.cat # TITLE: # DESCRIPTION: # DATA TYPE: cat