Class: Mlr::Strategy::Python

Inherits:
Object
  • Object
show all
Defined in:
lib/mlr/strategy/python.rb

Constant Summary collapse

SCRIPT =
<<~PYTHON
  import localization as lx
  P=lx.Project(mode='%{mode}',solver='%{solver}')
  %{anchors}
  t,label=P.add_target()
  %{measures}
  P.solve()
PYTHON

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(points:, mode: Mlr::MODE2D, solver: Mlr::SOLVER_LSE) ⇒ Python

Returns a new instance of Python.



19
20
21
22
23
# File 'lib/mlr/strategy/python.rb', line 19

def initialize(points:, mode: Mlr::MODE2D, solver: Mlr::SOLVER_LSE)
  @points = points
  @mode = mode
  @solver = solver
end

Class Method Details

.get_point(options) ⇒ Object



15
16
17
# File 'lib/mlr/strategy/python.rb', line 15

def self.get_point(options)
  new(options).run
end

Instance Method Details

#optionsObject



33
34
35
36
37
38
39
40
# File 'lib/mlr/strategy/python.rb', line 33

def options
  {
    anchors: get_anchors,
    measures: get_measures,
    mode: get_mode,
    solver: get_solver
  }
end

#runObject



25
26
27
28
29
30
31
# File 'lib/mlr/strategy/python.rb', line 25

def run
  # run python script
  PyCall.exec(SCRIPT % options)

  # get result from python
  make_point(PyCall.eval('t.loc'))
end