-
Notifications
You must be signed in to change notification settings - Fork 0
Add environment variable customization for solver paths #32
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
Conversation
Co-authored-by: ryanjoneil <6748953+ryanjoneil@users.noreply.github.com>
Co-authored-by: ryanjoneil <6748953+ryanjoneil@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for customizing solver executable paths via environment variables to handle non-standard installations across platforms.
- Introduces a
solver_executablehelper in the baseSolverclass to fetch paths from env vars with fallbacks. - Updates each solver (
CBC,CLP,CPLEX,GLPK,SCIP) to use the helper instead of hardcoded names. - Adds tests and documentation to cover default and custom solver path configurations.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/test_solver_paths.rb | Added tests for default and custom solver path commands |
| lib/rams/solvers/solver.rb | Introduced solver_executable helper method |
| lib/rams/solvers/scip.rb | Updated SCIP solver to use the helper for the executable name |
| lib/rams/solvers/glpk.rb | Updated GLPK solver to use the helper for the executable name |
| lib/rams/solvers/cplex.rb | Updated CPLEX solver to use the helper for the executable name |
| lib/rams/solvers/clp.rb | Updated CLP solver to use the helper for the executable name |
| lib/rams/solvers/cbc.rb | Updated CBC solver to use the helper for the executable name |
| docs/03-solver-configuration.md | Documented environment variable overrides for solver paths |
Comments suppressed due to low confidence (1)
tests/test_solver_paths.rb:30
- These tests verify only the first element of the command array. Consider adding assertions for the full
solver_commandoutput to ensure the rest of the flags and arguments remain correct.
assert_equal 'coin.cbc', command[0]
| def solver_command(_model_file, _solution_path, _args) | ||
| raise NotImplementedError | ||
| end | ||
|
|
Copilot
AI
Jun 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper method solver_executable is currently public. Consider moving it under a private section so it isn’t exposed as part of the public API.
| private | |
| def write_model_file(model) | |
| model_file = Tempfile.new ['', '.lp'] | |
| model_file.write model.to_lp | |
| model_file.close | |
| model_file | |
| end | |
| def get_solution(model, model_path) | |
| solution_path = model_path + '.sol' | |
| begin | |
| solve_and_parse model, model_path, solution_path | |
| ensure | |
| File.delete(solution_path) if File.exist?(solution_path) | |
| end | |
| end | |
| def solve_and_parse(model, model_path, solution_path) | |
| call_solver model, model_path, solution_path | |
| return RAMS::Solution.new(:unknown, nil, {}, {}) unless File.exist? solution_path | |
| parse_solution model, File.read(solution_path) | |
| end | |
| # rubocop:disable MethodLength | |
| def call_solver(model, model_path, solution_path) | |
| command = solver_command(model_path, solution_path, model.args) | |
| _, stdout, stderr, exit_code = Open3.popen3(*command) | |
| begin | |
| output = stdout.gets(nil) || '' | |
| error = output + (stderr.gets(nil) || '') | |
| puts output if model.verbose && output != '' | |
| raise error unless exit_code.value == 0 | |
| return output | |
| ensure | |
| stdout.close | |
| stderr.close | |
| end | |
| end | |
| # rubocop:enable MethodLength | |
| def solver_command(_model_file, _solution_path, _args) | |
| raise NotImplementedError | |
| end |
This PR adds the ability to customize solver executable paths through environment variables, addressing the issue where solver names might be different on different platforms or installed in custom locations.
Changes
Environment Variables Added
Each solver now supports customization via environment variables that override the default executable names:
RAMS_SOLVER_PATH_CBC- Override path for CBC (defaults tocoin.cbc)RAMS_SOLVER_PATH_CLP- Override path for CLP (defaults toclp)RAMS_SOLVER_PATH_CPLEX- Override path for CPLEX (defaults tocplex)RAMS_SOLVER_PATH_GLPK- Override path for GLPK (defaults toglpsol)RAMS_SOLVER_PATH_SCIP- Override path for SCIP (defaults toscip)Implementation
solver_executablehelper method to the baseSolverclass that checks for environment variables first, then falls back to defaultsUsage Examples
Testing
test_solver_paths.rb) with 10 test cases covering all solversDocumentation
The implementation is minimal and surgical, changing only what's necessary to add the requested functionality while preserving all existing behavior.
Fixes #31.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.