A client for JijZept Solver API.
Project description
JijZept Solver
Jij 製の数理最適化ソルバーである JijZept Solver を 、Web API 経由で実行するための クライアントパッケージです。以下に使用方法を説明します。 / Client package for executing JijZept Solver, Jij's mathematical optimization solver, via Web API. The following explains how to use it.
Quick Start
アクセストークンの取得 / Obtaining Access Token
JijZept Solver(無償WebAPI版) を使用するには、事前にアクセストークンを取得する必要があります。無償版の利用申請方法は以下の通りです。 / To use JijZept Solver (Free Web API version), you need to obtain an access token in advance. The application method for the free version is as follows.
利用申請方法 / Application Method
-
以下リンク先のフォームから利用申請を行ってください。 / Please apply for usage from the form at the following link.
申請フォーム / Application Form: JijZept Solver(無償WebAPI版) 利用申請フォーム / JijZept Solver (Free Web API version) Usage Application Form
-
申請されたメールアドレス宛に、アクセスに必要な情報(API サーバーのホスト名、アクセストークン)が届きます。 / The information required for access (API server hostname, access token) will be sent to the email address you applied with.
インストール / Installation
JijZept Solver のクライアントパッケージをインストールします / Install the JijZept Solver client package:
pip install jijzept-solver
環境変数の設定 / Environment Variable Setup
上記利用申請により入手した、以下の値を環境変数に設定します / Set the following values obtained from the above application as environment variables:
-
JIJZEPT_SOLVER_SERVER_HOST: API サーバーのホスト名 / API server hostname -
JIJZEPT_SOLVER_ACCESS_TOKEN: アクセストークン / Access token
設定例 / Configuration Examples
環境変数の設定例 / Environment variable configuration example:
export JIJZEPT_SOLVER_SERVER_HOST="API サーバーのホスト名 / API server hostname"
export JIJZEPT_SOLVER_ACCESS_TOKEN="アクセストークン / Access token"
または Python コード内で設定する例 / Or example of setting within Python code:
import os
os.environ["JIJZEPT_SOLVER_SERVER_HOST"] = "API サーバーのホスト名 / API server hostname"
os.environ["JIJZEPT_SOLVER_ACCESS_TOKEN"] = "アクセストークン / Access token"
リクエスト実行例 / Request Execution Example
実行例の中で JijModeling を使用するため、事前にインストールしておきます。 / Install JijModeling in advance as it is used in the execution example.
pip install jijmodeling
ナップサック問題を解く例 / Example of solving a knapsack problem:
import logging
import jijzept_solver
import jijmodeling as jm
logging.basicConfig(level=logging.INFO)
# ナップサック問題を定義 / Define knapsack problem
v = jm.Placeholder("v", ndim=1) # アイテムの価値 / Item values
w = jm.Placeholder("w", ndim=1) # アイテムの重さ / Item weights
W = jm.Placeholder("W") # ナップサックの容量 / Knapsack capacity
N = v.len_at(0, latex="N") # アイテム数 / Number of items
x = jm.BinaryVar("x", shape=(N,)) # 決定変数 / Decision variables
i = jm.Element("i", belong_to=(0, N))
problem = jm.Problem("Knapsack", sense=jm.ProblemSense.MAXIMIZE)
problem += jm.sum(i, v[i] * x[i]) # 目的関数:価値の最大化 / Objective function: maximize value
problem += jm.Constraint("weight", jm.sum(i, w[i] * x[i]) <= W) # 重量制約 / Weight constraint
# インスタンスデータ / Instance data
instance_data = {
"v": [10, 13, 18, 31, 7, 15], # アイテムの価値 / Item values
"w": [11, 15, 20, 35, 10, 33], # アイテムの重さ / Item weights
"W": 47, # ナップサックの容量 / Knapsack capacity
}
# OMMX インスタンスを作成 / Create OMMX instance
interpreter = jm.Interpreter(instance_data)
instance = interpreter.eval_problem(problem)
# APIにリクエストを実行 / Execute API request
solution = jijzept_solver.solve(instance, time_limit_sec=2.0)
print(f"Value of the objective function: {solution.objective}")
API リファレンス / API Reference
JijZept Solver を使用して最適化問題を解きます。 / Solve optimization problems using JijZept Solver.
パラメータ: / Parameters:
ommx_instance(Instance): OMMX インスタンス / OMMX instancetime_limit_sec(float): 最大求解時間(秒) / Maximum solving time (seconds)
戻り値: / Return Value:
Solution: OMMX ソリューション / OMMX solution
例: / Example:
solution = jijzept_solver.solve(
ommx_instance=problem_instance,
time_limit_sec=2.0
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file jijzept_solver-1.0.0.tar.gz.
File metadata
- Download URL: jijzept_solver-1.0.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f658cfffb9b01292f55400c75d2aba8634dd43efa169d8210957f08e3c2eac35
|
|
| MD5 |
6f141eb010bb926b7e60299d75bfe17a
|
|
| BLAKE2b-256 |
be51f6eb9b1a7d2d5b8f0199a0293c319d7c9fe5f6e2b497e8553099e07bfc6b
|
Provenance
The following attestation bundles were made for jijzept_solver-1.0.0.tar.gz:
Publisher:
release_client.yml on Jij-Inc/JijZeptSolverAPI
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jijzept_solver-1.0.0.tar.gz -
Subject digest:
f658cfffb9b01292f55400c75d2aba8634dd43efa169d8210957f08e3c2eac35 - Sigstore transparency entry: 274352448
- Sigstore integration time:
-
Permalink:
Jij-Inc/JijZeptSolverAPI@6a60655759f2d05ff026a0a97d0d389734e5ea15 -
Branch / Tag:
refs/tags/client-v1.0.0 - Owner: https://github.com/Jij-Inc
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_client.yml@6a60655759f2d05ff026a0a97d0d389734e5ea15 -
Trigger Event:
push
-
Statement type: