scipopt / SCIP.jl

Julia interface to SCIP solver
MIT License
95 stars 24 forks source link

Get variable and constraint names #204

Closed matbesancon closed 3 years ago

matbesancon commented 3 years ago

Many MOI tests require getting variable and constraint indices by name.

The two solutions are:

  1. keep a dictionary of names for each like HiGHS.jl does. Might be simpler to build and test? But we create yet another pair of dicts, this wrapper has a lot of them between SCIP.Optimizer and SCIPData
  2. fetch the names from SCIP directly, see following function:
/** parses the given string for a variable name and stores the variable in the corresponding pointer if such a variable
 *  exits and returns the position where the parsing stopped
 *
 *  @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
 *          SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
 *
 *  @pre This method can be called if @p scip is in one of the following stages:
 *       - \ref SCIP_STAGE_PROBLEM
 *       - \ref SCIP_STAGE_TRANSFORMING
 *       - \ref SCIP_STAGE_INITPRESOLVE
 *       - \ref SCIP_STAGE_PRESOLVING
 *       - \ref SCIP_STAGE_EXITPRESOLVE
 *       - \ref SCIP_STAGE_PRESOLVED
 *       - \ref SCIP_STAGE_SOLVING
 */
SCIP_EXPORT
SCIP_RETCODE SCIPparseVarName(
   SCIP*                 scip,               /**< SCIP data structure */
   const char*           str,                /**< string to parse */
   SCIP_VAR**            var,                /**< pointer to store the problem variable, or NULL if it does not exit */
   char**                endptr              /**< pointer to store the final string position if successful */
   );

Opinions? @odow @rschwarz @etadewal

matbesancon commented 3 years ago

after trying things for a bit, calling SCIP methods directly seems a bit brittle for now (I'm never sure in which state SCIP is), we'll go for yet anoth dict

matbesancon commented 3 years ago

edit from @fserra : SCIPfindVar could do the job we want here

matbesancon commented 3 years ago

tackled in #205

rschwarz commented 3 years ago

I believe this was implemented at some point, letting SCIP store the names. But it lead to errors, so it was removed again. Unfortunately, I can't remember the details. So, bon courage!

odow commented 3 years ago

Keeping a dictionary isn't too hard. Check the var_to_name stuff here: https://github.com/jump-dev/MathOptInterface.jl/blob/master/src/Utilities/model.jl

matbesancon commented 3 years ago

This was done with #205

matbesancon commented 3 years ago

it does not yet follow the MOI convention that getting a variable name when several have the same should throw though