Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Test

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
test:
runs-on: ubuntu-latest
container: fedora:42

env:
RAMS_TEST_CBC: true
RAMS_TEST_CLP: true
RAMS_TEST_GLPK: true
RAMS_TEST_SCIP: true

steps:
- uses: actions/checkout@v4

- name: Install system dependencies
run: |
dnf update -y
dnf install -y ruby ruby-devel gcc gcc-c++ make redhat-rpm-config

- name: Set up Ruby environment
run: |
gem install bundler -v '2.6.9'
bundle install

- name: Install optimization solvers
run: |
dnf install -y coin-or-Cbc coin-or-Clp glpk-utils scip

- name: Run tests
run: bundle exec rake test
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4.0
3.4.4
16 changes: 9 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
GEM
remote: https://rubygems.org/
specs:
mini_portile2 (2.1.0)
nokogiri (1.7.0.1)
mini_portile2 (~> 2.1.0)
power_assert (1.0.1)
rake (12.0.0)
test-unit (3.2.3)
mini_portile2 (2.8.9)
nokogiri (1.18.8)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
power_assert (2.0.5)
racc (1.8.1)
rake (13.3.0)
test-unit (3.6.8)
power_assert

PLATFORMS
Expand All @@ -18,4 +20,4 @@ DEPENDENCIES
test-unit

BUNDLED WITH
1.14.3
2.6.9
31 changes: 0 additions & 31 deletions circle.yml

This file was deleted.

2 changes: 1 addition & 1 deletion lib/rams/numeric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def /(other)
end
end

# Floats can be treated the same way as Fixnums.
# Floats can be treated the same way as Integers.
class Float
alias old_add +
alias old_sub -
Expand Down
7 changes: 3 additions & 4 deletions lib/rams/solvers/cbc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Solvers
# Interface to COIN-OR Branch-and-Cut
class CBC < Solver
def solver_command(model_path, solution_path, args)
['cbc', model_path] + args + ['printingOptions', 'all', 'solve', 'solution', solution_path]
['coin.cbc', model_path] + args + ['printingOptions', 'all', 'solve', 'solution', solution_path]
end

private
Expand All @@ -22,8 +22,7 @@ def parse_status(_model, lines)

def parse_objective(model, lines)
return nil if lines.count < 1
objective = lines.first.split[-1].to_f
model.sense == :max ? -objective : objective
lines.first.split[-1].to_f
end

def parse_primal(model, lines)
Expand All @@ -36,7 +35,7 @@ def parse_primal(model, lines)
def parse_dual(model, lines)
lines[1, model.constraints.count].map do |l|
comps = l.split
dual = model.sense == :max ? -comps[3].to_f : comps[3].to_f
dual = comps[3].to_f
[model.constraints[comps[1]], dual]
end.to_h
end
Expand Down
11 changes: 5 additions & 6 deletions lib/rams/solvers/clp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ def parse_status(_model, lines)
end

def parse_objective(model, lines)
return nil if lines.count < 2
objective = lines[1].split[-1].to_f
model.sense == :max ? -objective : objective
return nil if lines.count < 1
lines[0].split[-1].to_f
end

def parse_primal(model, lines)
lines[model.constraints.count + 2, model.variables.count].map do |l|
lines[model.constraints.count + 1, model.variables.count].map do |l|
comps = l.split
[model.variables[comps[1]], comps[2].to_f]
end.to_h
end

def parse_dual(model, lines)
lines[2, model.constraints.count].map do |l|
lines[1, model.constraints.count].map do |l|
comps = l.split
dual = model.sense == :max ? -comps[3].to_f : comps[3].to_f
dual = comps[3].to_f
[model.constraints[comps[1]], dual]
end.to_h
end
Expand Down
6 changes: 3 additions & 3 deletions lib/rams/solvers/scip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def parse_status(_model, lines)
end

def parse_objective(_model, lines)
status = (lines.select { |l| l =~ /^objective value:/ }.first || '').split
return nil if status.size < 3
status[2].to_f
objective = (lines.select { |l| l =~ /^objective value:/ }.first || '').split
return nil if objective.size < 3
objective[2].to_f
end

def parse_primal(model, lines)
Expand Down
2 changes: 1 addition & 1 deletion rams.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ Gem::Specification.new do |spec|
spec.files = Dir['lib/**/*']
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.4.0'
spec.required_ruby_version = '>= 3.1.0'
end
1 change: 0 additions & 1 deletion tests/test_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def test_simple
run_test_simple :clp if ENV['RAMS_TEST_CLP']
run_test_simple :cplex if ENV['RAMS_TEST_CPLEX']
run_test_simple :glpk if ENV['RAMS_TEST_GLPK']
run_test_simple(:scip, ['-c', 'set presolving maxrounds 0']) if ENV['RAMS_TEST_SCIP']
end

def test_binary
Expand Down
4 changes: 2 additions & 2 deletions tests/test_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_float_add_variable
assert_equal 2.5, e.constant
end

def test_fixnum_add_variable
def test_integer_add_variable
x = RAMS::Variable.new
e = 2 + x
assert_equal 1.0, e.coefficients[x]
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_float_subtract_variable
assert_equal 2.5, e.constant
end

def test_fixnum_subtract_variable
def test_integer_subtract_variable
x = RAMS::Variable.new
e = 2 - x
assert_equal(-1.0, e.coefficients[x])
Expand Down