Skip to content

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

@willu47

Description

@willu47

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions