Skip to content

Commit

Permalink
Merge pull request #1 from RelationalAI/zhu-add-more-tests
Browse files Browse the repository at this point in the history
Add/fix some tests, plus some cleanup and formatting
  • Loading branch information
chriscoey authored Sep 18, 2023
2 parents 2e66744 + f43b64b commit d4b836f
Show file tree
Hide file tree
Showing 36 changed files with 238 additions and 254 deletions.
10 changes: 10 additions & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Configuration file for JuliaFormatter.jl
# For more information, see: https://domluna.github.io/JuliaFormatter.jl/stable/config/

verbose = true
format_markdown = true
remove_extra_newlines = true
always_for_in = true
conditional_to_if = true
always_use_return = true
format_docstrings = true
31 changes: 31 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: FormatCheck
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/setup-julia@latest
with:
version: '1'
- uses: actions/checkout@v1
- name: Format check
shell: julia --color=yes {0}
run: |
using Pkg
# If you update the version, also update the style guide docs.
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
using JuliaFormatter
format("src", verbose=true)
format("test", verbose=true)
out = String(read(Cmd(`git diff`)))
if isempty(out)
exit(0)
end
@error "Some files have not been formatted!"
write(stdout, out)
exit(1)
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0]
- Initial release

- Initial release
80 changes: 46 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Currently, JSON is used for serialization, and only optimization
solvers and constraint programming solvers are supported.

## API

The main API is `solve` which takes a JSON request or Julia dictionary
and a solver and returns a response.

Expand All @@ -17,20 +18,22 @@ using SolverAPI
import HiGHS

tiny_min = Dict(
"version" => "0.1",
"sense" => "min",
"variables" => ["x"],
"constraints" => [["==", "x", 1], ["Int", "x"]],
"objectives" => ["x"],
)
"version" => "0.1",
"sense" => "min",
"variables" => ["x"],
"constraints" => [["==", "x", 1], ["Int", "x"]],
"objectives" => ["x"],
)

solve(tiny_min, HiGHS.Optimizer())
```

## Format

### Request

Request format example:

```json
{
"version": "0.1",
Expand Down Expand Up @@ -58,48 +61,56 @@ Request format example:
}
}
```

Required fields:
- `version`: [String] The version of the API that is used.
- `options`: [Array] Options, such as the time limit, if the
model should be printed, or general solver attributes. For a
complete list, please refer to the documentation of the solver.
- `sense`: [String] One of `feas`, `min`, or `max`
- `variables`: [Array] A list of variables that are used in the model.
- `constraints`: [Array] A list of constraints. Each constraint
contains an operation and a set of arguments, such as `["==", "x", 1]`.
- `objectives`: [Array] The objective.

- `version`: [String] The version of the API that is used.
- `options`: [Array] Options, such as the time limit, if the
model should be printed, or general solver attributes. For a
complete list, please refer to the documentation of the solver.
- `sense`: [String] One of `feas`, `min`, or `max`
- `variables`: [Array] A list of variables that are used in the model.
- `constraints`: [Array] A list of constraints. Each constraint
contains an operation and a set of arguments, such as `["==", "x", 1]`.
- `objectives`: [Array] The objective.

#### Options

We always support the following options:
- `silent`: [Bool] Controls if the solver prints any logs.
- `time_limit_sec`: [Float64] Limits the total time expended. The optimization
returns a `TIME_LIMIT` status.
- `print_only`: [Bool] If set to true the model will only be printed
and not solved.
- `print_format`: [String] If and how the model should be
printed. Currently supported formats: default, LaTex, MOF, LP, MPS, NL.

- `silent`: [Bool] Controls if the solver prints any logs.
- `time_limit_sec`: [Float64] Limits the total time expended. The optimization
returns a `TIME_LIMIT` status.
- `print_only`: [Bool] If set to true the model will only be printed
and not solved.
- `print_format`: [String] If and how the model should be
printed. Currently supported formats: MOI, LaTeX, MOF, LP, MPS, NL.

### Response

Response format examples:

```json
{
"version": "0.1",
"results": [
{
"objective_value": 0.0,
"primal_status": "FEASIBLE_POINT",
"sol_names": [
"names": [
"\"x\""
],
"sol_values": [
"values": [
1
]
}
],
"termination_status": "OPTIMAL"
}
```

Example with a model error:

```json
{
"version": "0.1",
Expand All @@ -114,6 +125,7 @@ Example with a model error:
```

Example with printing and no solving:

```json
{
"model_string": "{\"name\":\"MathOptFormat Model\",\"version\":{\"major\":1,\"minor\":4},\"variables\":[{\"name\":\"x\"}],\"objective\":{\"sense\":\"min\",\"function\":{\"type\":\"Variable\",\"name\":\"x\"}},\"constraints\":[{\"name\":\"c1\",\"function\":{\"type\":\"ScalarAffineFunction\",\"terms\":[{\"coefficient\":1.0,\"variable\":\"x\"}],\"constant\":0.0},\"set\":{\"type\":\"EqualTo\",\"value\":1.0}},{\"function\":{\"type\":\"Variable\",\"name\":\"x\"},\"set\":{\"type\":\"Integer\"}}]}",
Expand All @@ -123,16 +135,16 @@ Example with printing and no solving:
```

Required fields:
- `version`: [String] The version of the API that is used.
- `termination_status`: [String] The MOI termination status.

- `version`: [String] The version of the API that is used.
- `termination_status`: [String] The MOI termination status.

Optional fields:
- `results`: [Array] The results array. Depending on
the optimization none, one, or multiple results will be
present. Each result will contain multiple fields describing the
solution, such as `objective_value`, `primal_status`,
`sol_names`, and `sol_values`.
- `errors`: [Array] None, one, or multiple errors that were present.
- `model_string`: [String] If requested via `print_format` the model
as a string.

- `results`: [Array] The results array. Zero, one, or multiple
results will be present. Each result will contain multiple fields
describing the solution, such as `objective_value`, `primal_status`,
`names`, and `values`.
- `errors`: [Array] None, one, or multiple errors that were present.
- `model_string`: [String] If requested via `print_format` the model
as a string.
Loading

0 comments on commit d4b836f

Please sign in to comment.