Class: Quicopt::Result
- Inherits:
-
Data
- Object
- Data
- Quicopt::Result
- Defined in:
- lib/quicopt/client.rb
Overview
A finished solve, parsed from the service's result JSON.
objective and feasible are nil where the outcome leaves them undefined —
a model with nothing to feasibility-check, or a run that found no solution.
display is the framed, ready-to-print summary the service renders the same
way for every kind of model — print it rather than formatting your own.
structures holds the Arrangement of each permutation and the Grouping
of each partition the model declares, by name, and is empty for a model with
none.
Instance Attribute Summary collapse
-
#display ⇒ Object
readonly
Returns the value of attribute display.
-
#feasible ⇒ Object
readonly
Returns the value of attribute feasible.
-
#job_id ⇒ Object
readonly
Returns the value of attribute job_id.
-
#objective ⇒ Object
readonly
Returns the value of attribute objective.
-
#solution ⇒ Object
readonly
Returns the value of attribute solution.
-
#solve_time_seconds ⇒ Object
readonly
Returns the value of attribute solve_time_seconds.
-
#solver_data ⇒ Object
readonly
Returns the value of attribute solver_data.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#structures ⇒ Object
readonly
Returns the value of attribute structures.
Class Method Summary collapse
-
.arrangement(json) ⇒ Object
private
One structure's value from the result JSON, where items, slots and parts count from 1: a permutation's
Arrangement, a partition'sGrouping, ornilwhen none came back. -
.from_json(body) ⇒ Result
Build a
Resultfrom the service's decoded result JSON.
Instance Method Summary collapse
-
#model_class ⇒ String?
The kind of model the service recognised (LP/MILP/QUBO/…), or
nilif it did not report one. -
#warn_if_lowered ⇒ Result
private
Warn when the service ran this solve for less time than its
time_limitasked for.
Instance Attribute Details
#display ⇒ Object (readonly)
Returns the value of attribute display
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def display @display end |
#feasible ⇒ Object (readonly)
Returns the value of attribute feasible
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def feasible @feasible end |
#job_id ⇒ Object (readonly)
Returns the value of attribute job_id
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def job_id @job_id end |
#objective ⇒ Object (readonly)
Returns the value of attribute objective
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def objective @objective end |
#solution ⇒ Object (readonly)
Returns the value of attribute solution
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def solution @solution end |
#solve_time_seconds ⇒ Object (readonly)
Returns the value of attribute solve_time_seconds
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def solve_time_seconds @solve_time_seconds end |
#solver_data ⇒ Object (readonly)
Returns the value of attribute solver_data
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def solver_data @solver_data end |
#status ⇒ Object (readonly)
Returns the value of attribute status
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def status @status end |
#structures ⇒ Object (readonly)
Returns the value of attribute structures
74 75 76 |
# File 'lib/quicopt/client.rb', line 74 def structures @structures end |
Class Method Details
.arrangement(json) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
One structure's value from the result JSON, where items, slots and parts
count from 1: a permutation's Arrangement, a partition's Grouping, or
nil when none came back.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/quicopt/client.rb', line 100 def self.arrangement(json) return nil if json.nil? if json.key?("part_of") return Grouping.new(part_of: json["part_of"].map { |b| b.to_i - 1 }, size_of: json["size_of"].map(&:to_i)) end Arrangement.new(item_at: json["item_at"].map { |i| i.to_i - 1 }, slot_of: json["slot_of"].map { |k| k.to_i - 1 }) end |
.from_json(body) ⇒ Result
Build a Result from the service's decoded result JSON.
Missing optional keys default rather than raise, so a partial result (e.g. a heuristic backend that reports no objective) still parses.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/quicopt/client.rb', line 83 def self.from_json(body) new(job_id: body["job_id"].to_s, status: body["status"].to_s, objective: body["objective"], feasible: body["feasible"], solution: body["solution"] || {}, solve_time_seconds: body["solve_time_seconds"] || 0.0, solver_data: body["solver_data"] || {}, display: body["display"].to_s, structures: (body["structures"] || {}).transform_values { |s| arrangement(s) }) end |
Instance Method Details
#model_class ⇒ String?
The kind of model the service recognised
(LP/MILP/QUBO/…), or nil if it did not report
one.
132 133 134 |
# File 'lib/quicopt/client.rb', line 132 def model_class solver_data["model_class"] end |
#warn_if_lowered ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Warn when the service ran this solve for less time than its time_limit
asked for. The service grants at most its maximum and reports what was
asked and what it granted side by side in solver_data.
117 118 119 120 121 122 123 124 125 |
# File 'lib/quicopt/client.rb', line 117 def warn_if_lowered asked = solver_data["time_limit_s"] granted = solver_data["time_budget_s"] if asked && granted && granted < asked warn "quicopt: the service ran this solve for #{Format.number(granted.to_f)} s, not the " \ "#{Format.number(asked.to_f)} s asked for: #{Format.number(granted.to_f)} s is the most it grants" end self end |