Add environment variable customization for solver paths#32
Merged
ryanjoneil merged 3 commits intomainfrom Jun 24, 2025
Merged
Conversation
Co-authored-by: ryanjoneil <6748953+ryanjoneil@users.noreply.github.com>
Co-authored-by: ryanjoneil <6748953+ryanjoneil@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Make solver paths customization through environment variables
Add environment variable customization for solver paths
Jun 24, 2025
There was a problem hiding this comment.
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]
| @@ -60,6 +60,11 @@ def solver_command(_model_file, _solution_path, _args) | |||
| raise NotImplementedError | |||
| end | |||
|
|
|||
There was a problem hiding this comment.
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.
Suggested change
| 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.