jijzept 1.18.5

Creator: bradpython12

Last updated:

Add to Cart

Description:

jijzept 1.18.5

JijZept Quick Start






How to get started with JijZept
The minimal sample code as follows:
import jijmodeling as jm
import jijzept as jz

x = jm.BinaryVar('x')
y = jm.BinaryVar('y')
problem = jm.Problem('sample_problem')
problem += - x * y

sampler = jz.JijSASampler(config='config.toml')
response = sampler.sample_model(problem, {})

print(response)

Write a configuration file for connecting to JijZept in config.toml and put it in the config argument of the Sampler constructor.
The configuration file should be written in TOML format as follows.
[default]
url = "***"
token = "****"

Copy and paste the assigned API endpoint into the url and your token into token in the configure file.
またデフォルトでは同期モード になっているため、APIに投げて計算が終わるで待ってから解を得ることになります。
同期モードをオフにして非同期でJijZeptを使うには以下の手順で答えを得ることができます。
async mode
非同期モードでAPIを使いたい場合は、.sample_* の引数で、async=False にして同期モードをオフにする必要があります。
サンプルコード
import jijmodeling as jm
import jijzept as jz

from jijzept.response import APIStatus

x = jm.BinaryVar('x')
y = jm.BinaryVar('y')
problem = jm.Problem('sample_problem')
problem += - x * y

sampler = jz.JijSASampler(config='config.toml')
response = sampler.sample_model(problem, {}, sync=False)


if response.status == APIStatus.SUCCESS:
print(response)
elif response.status == APIStatus.PENDING:
print('Solver status: PENDING')
else:
print('Error')

非同期モードでも .sample_* の返り値は 同期モードと同じくJijModelingResponse クラスです。
ですが、解が入っていない可能性があります(非同期モードでも一度だけ解を取りに行っているので計算時間が短いと解をもっている可能性もあります)。
解を取りに行くためのコードが
response = response.get_result()

です。また.get_resultは返り値をもつ非破壊メソッドです。
計算が終了したかどうかはget_resultの返り値の.status変数で確認することができます。
from jijzept.response import APIStatus

if response.status == APIStatus.SUCCESS:
print(response)
elif response.status == APIStatus.PENDING:
print('Solver status: PENDING')
else:
print('Error')

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.