Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Jul 26, 2023
1 parent c88e202 commit d2034e2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ __pycache__
.venv
.ruff_cache

demo/cqo1.ptf
cqo1.ptf
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

SHELL=/bin/bash


.PHONY: install
install: ## Install a virtual environment
@poetry install -vv
Expand All @@ -14,9 +15,19 @@ fmt: ## Run autoformatting and linting
clean: ## Clean up caches and build artifacts
@rm -rf .pytest_cache/
@rm -rf .ruff_cache/
@rm -f **cqo1.ptf
@find . -type f -name '*.py[co]' -delete -or -type d -name __pycache__ -delete


# Define the demo target
.PHONY: demo
demo: install ## Run a demo
@poetry run demo

.PHONY: help
help: ## Display this help screen
@echo
@echo -e "\033[1mAvailable commands:\033[0m"
@echo
@grep -E '^[a-z.A-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-18s\033[0m %s\n", $$1, $$2}' | sort
@echo
10 changes: 7 additions & 3 deletions demo/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
license.upsert()


if __name__ == "__main__":
def main():
with fusion.Model("cqo1") as M:
# this is optional, just to be safe...
M.putlicensepath(license.current())
Expand Down Expand Up @@ -36,14 +36,14 @@
# z1[0] >= sqrt(z1[1]^2 + z1[2]^2)
# and 2.0 z2[0] z2[1] >= z2[2]^2
qc1 = M.constraint("qc1", z1, fusion.Domain.inQCone())
qc2 = M.constraint("qc2", z2, fusion.Domain.inRotatedQCone())
M.constraint("qc2", z2, fusion.Domain.inRotatedQCone())

# Set the objective function to (y[0] + y[1] + y[2])
M.objective("obj", fusion.ObjectiveSense.Minimize, fusion.Expr.sum(y))

# Solve the problem
M.solve()
M.writeTask("cqo1.ptf")
# M.writeTask("cqo1.ptf")

# Get the linear solution values
solx = x.level()
Expand All @@ -56,3 +56,7 @@
qc1sn = qc1.dual()
print("qc1 levels = %s" % str(qc1lvl))
print("qc1 dual conic var levels = %s" % str(qc1sn))


if __name__ == "__main__":
main()
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ black = "23.3.0"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
demo = "demo.demo:main"

[tool.ruff]
select = ["E", "F", "I"]
line-length = 100
Expand Down

0 comments on commit d2034e2

Please sign in to comment.