Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: CPLEX results processing does not return zero values #214

Open
willu47 opened this issue Feb 1, 2024 · 0 comments
Open

[Bug]: CPLEX results processing does not return zero values #214

willu47 opened this issue Feb 1, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@willu47
Copy link
Member

willu47 commented Feb 1, 2024

The Issue

Some users need to extract zero values from a CPLEX solution file.

Expected Behavior

Given a CPLEX solution file, the otoole results cplex csv... command should write out a folder of CSV files, and those CSV files should contain zero-valued rows.

Steps To Reproduce

No response

Log output

No response

Operating System

MacOS

What version of otoole are you running?

v1.1.2

Possible Solution

Replace the ReadCPLEX class with the following

class ReadCplex(ReadWideResults):
    """Read a CPLEX solution file into memory"""

    def _convert_to_dataframe(self, file_path: Union[str, TextIO]) -> pd.DataFrame:
        """Reads a Cplex solution file into a pandas DataFrame

        Arguments
        ---------
        user_config : Dict[str, Dict]
        file_path : Union[str, TextIO]
        """
        df = pd.read_xml(file_path, xpath=".//variable", parser="etree")
        df[["Variable", "Index"]] = df["name"].str.split("(", expand=True)
        df["Index"] = df["Index"].str.replace(")", "", regex=False)
        LOGGER.debug(df)
        df = df.reset_index().rename(columns={"value": "Value"})
        return df[["Variable", "Index", "Value"]].astype({"Value": float})

Anything else?

No response

@willu47 willu47 added the bug Something isn't working label Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant