amor 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46282019baa1044124775c91d8e2aae1c46156a5
4
- data.tar.gz: 4cbb2861f562e55943517188594c84cffb22f4f4
3
+ metadata.gz: 31492f2a4a6321ec6ad50a028c7e0a072c32131b
4
+ data.tar.gz: 2d11c7147c51de95267d0ae69ddefcd858fab2c3
5
5
  SHA512:
6
- metadata.gz: f2b827c94fc45987b12ece82d7eee41528933ee3df684eef112704239f7799e101003b8e639ff54b01aee73ca17c6b8d74a83afaafa9037985c067d1ad51ee0c
7
- data.tar.gz: 1d7864300b2030f1b1c2ad2dc276ab75d5282b031d1f6b2360a0b35ace42af032ac6d78184a1e94dd6c6ccd88fb6f789090eebace885164e9ec9265b7804de48
6
+ metadata.gz: 8b6a4b028958ab03e30430cd6c75b5df531944eaffe99628c2df3d8600f98c98f8fbb2eeda4280e17a58317c112a9fe540204004d2dfe6663e72fdf8d6b70ef4
7
+ data.tar.gz: 5efcbc2c466fac5623951a281753b1a3f995cc2cd85b20a6dfe6ec24dd54288ad2e17c64bdd336795f12c1b1e090cf1741d586187d87565b46be6d2b7fad5db0
data/README.md CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Visit <a href='http://amor-gem.com'>amor-gem.com</a> for further information
22
22
 
23
23
  ## Contributing
24
24
 
data/amor.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["me@fdahms.com"]
11
11
  spec.summary = "A versatile, yet simple modelling language for mathematical programming"
12
12
  spec.description = "AMoR is a Ruby DSL for mathematical programming. It allows to simply define a mathematical program, but gives you all the features from Ruby for more complex projects"
13
- spec.homepage = ""
13
+ spec.homepage = "http://amor-gem.com"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
data/lib/amor/model.rb CHANGED
@@ -3,7 +3,7 @@ require 'amor/objective'
3
3
  module Amor
4
4
  class Model
5
5
 
6
- attr_reader :objective, :constraints
6
+ attr_reader :constraints, :solved, :bounded
7
7
 
8
8
  def initialize
9
9
  @variables = Array.new
@@ -13,10 +13,25 @@ module Amor
13
13
 
14
14
  # Return the variable for that index if already existing or a new one
15
15
  def x(index)
16
- @variables[@indices[index] ||= @indices.size] ||= Variable.new(self, index)
16
+ variable = @variables[@indices[index] ||= @indices.size] ||= Variable.new(self, index)
17
+ if @solved
18
+ variable.value || 0
19
+ else
20
+ variable
21
+ end
17
22
  end
18
23
  alias :var :x
19
24
 
25
+ def objective
26
+ if @solved
27
+ @objective_value
28
+ else
29
+ @objective
30
+ end
31
+ end
32
+ alias :obj :objective
33
+
34
+
20
35
  # Add a minimization objective
21
36
  def min(expression)
22
37
  @objective = Objective.new(:minimize, expression)
@@ -114,5 +129,39 @@ module Amor
114
129
  variable.lb = 0
115
130
  return variable
116
131
  end
132
+
133
+ def scip
134
+ self.save_lp('__temp.lp')
135
+ scip_result = `scip -f __temp.lp`
136
+ File.delete('__temp.lp')
137
+
138
+ solution_section = false
139
+ scip_result.each_line do |line|
140
+ if line =~ /problem is solved \[([\w\s]*)\]/
141
+ @solved = true
142
+ if $1 == 'optimal solution found'
143
+ @bounded = true
144
+ elsif $1 == 'unbounded'
145
+ @bounded = false
146
+ else
147
+ raise 'Unknown solve status'
148
+ end
149
+ end
150
+
151
+ solution_section = true if line =~ /primal solution:/
152
+ solution_section = false if line =~ /Statistics/n
153
+
154
+ if solution_section
155
+ @objective_value = $1 if line =~ /objective value:\s*([\.\d]+)/
156
+ if line =~ /x(\d+)\s*([\.\d]+)/
157
+ @variables[$1.to_i-1].value = $2.to_f
158
+ end
159
+ end
160
+ end
161
+
162
+ rescue Errno::ENOENT => e
163
+ puts "Could not find SCIP. Please make sure that SCIP is installed and you can execute 'scip'."
164
+ raise e
165
+ end
117
166
  end
118
167
  end
data/lib/amor/variable.rb CHANGED
@@ -3,7 +3,7 @@ module Amor
3
3
 
4
4
  attr_reader :model, :index
5
5
 
6
- attr_accessor :type, :lb, :ub
6
+ attr_accessor :type, :lb, :ub, :value
7
7
  alias :lower_bound :lb
8
8
  alias :upper_bound :ub
9
9
 
data/lib/amor/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Amor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Dahms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2014-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -100,7 +100,7 @@ files:
100
100
  - spec/amor/objective_spec.rb
101
101
  - spec/amor/variable_spec.rb
102
102
  - spec/spec_helper.rb
103
- homepage: ''
103
+ homepage: http://amor-gem.com
104
104
  licenses:
105
105
  - MIT
106
106
  metadata: {}
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.2.1
123
+ rubygems_version: 2.2.2
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: A versatile, yet simple modelling language for mathematical programming