Repository of optimization functions for research projects, teaching and learning
Resources
- Introduction to Optimization1.
This repository collects optimization examples for teaching and research. Example Optimization Code/ holds the course examples from Laurent Lessard's Introduction to Optimization course (linked above): Julia/JuMP scripts that the folder notes say were converted from Julia 0.6 to Julia 1.10, and Python ports that use PuLP, CVXPY and GEKKO. Optimization Functions/ holds a Jupyter notebook that introduces linear programming with Google OR-Tools. Cosimulation/ couples PowerWorld Simulator and Julia PowerModels: it exports a solved PowerWorld case to a MATPOWER file, solves an AC power flow on that file in PowerModels, and writes the solution back into PowerWorld.
flowchart LR
A["Lessard course examples<br/>(originally Julia 0.6)"] --> B["Julia 1.10 scripts<br/>JuMP with Clp, Cbc, GLPK,<br/>Ipopt, Gurobi"]
A --> C["Python ports<br/>PuLP, CVXPY, GEKKO"]
N["Linear_Programming.ipynb<br/>OR-Tools GLOP"] --> R["Printed solutions<br/>and plots"]
B --> R
C --> R
P["PowerWorld .pwb case"] --> M["Cosimulation/main.py<br/>SimAuto via esa"]
M --> F["MATPOWER .m file"]
F --> J["PowerModels solve_ac_pf<br/>(Julia via PyJulia)"]
J --> O["JSON written back to PowerWorld;<br/>bus, gen, branch CSVs"]
O -.->|"next pass (3 in total)"| M
The teaching examples are independent scripts. Each one builds a small model from data written in the file, solves it, and prints or plots the result. The Cosimulation loop runs three passes (while count < 3 in main.py).
| Folder | What it contains | Main contributor (git history) | Start here |
|---|---|---|---|
Cosimulation/ |
PowerWorld to PowerModels loop: main.py and four helper modules |
Philipellon (5 commits, 2025) | main.py |
Example Optimization Code/ |
20 Julia scripts in Julia 1 - 7, Julia 8 - 16 and Julia 17 - 25; 39 Python ports in Python/ (linear, convex, nonconvex and combinatorial) |
Philipellon (Python, 72 commits); EricKellerRE (Julia, 19 commits) | Julia 1 - 7/Top Brass.jl or Python/Linear Programming/House.py |
Optimization Functions/ |
Linear programming/: an OR-Tools linear programming notebook and a short Intro.md |
Jonathan Snodgrass (1 commit, 2022) | Linear programming/Linear_Programming.ipynb |
Root files and data:
| Path | What it is |
|---|---|
README.md |
This file |
requirements.txt |
Python packages imported by the code (added 2026-09-27) |
LICENSE |
MIT License, copyright 2022 Research Group of Professor Tom Overbye |
.gitignore, .idea/ |
Git ignore rules and JetBrains IDE project settings |
Example Optimization Code/Julia 8 - 16/uy_data.csv |
100 rows of (u, y) pairs for the moving-average examples; no header row |
- Tools:
- Julia examples: Julia 1.10 or later. There is no
Project.toml, so install the packages in step 2 by hand. Cosimulation/: Windows, PowerWorld Simulator with a SimAuto licence, and Julia (the folder ReadMe names Julia 1.11.4).- Gurobi, installed and licensed, for
Hovercraft 1-D.jl,Hovercraft.jl,Norm of 1-D Datasets.jlandPolynomial Regression v0.jl(Julia 8 - 16).Data Norms.pyanddata Norms1.py(Python/Convex Programming) call Gurobi through CVXPY (solver=cp.GUROBI) and need only thegurobipypackage (step 6); its bundled size-limited licence covers these small models.
- Julia examples: Julia 1.10 or later. There is no
- Julia packages, taken from the
usinglines. In the Julia REPL:using Pkg Pkg.add(["JuMP", "Clp", "Cbc", "GLPK", "HiGHS", "Ipopt", "ECOS", "SCS", "NonlinearSolve", "StaticArrays", "NamedArrays", "CSV", "DataFrames", "PyPlot"]) Pkg.add("Gurobi") # needs Gurobi installed and licensed Pkg.add(["PowerModels", "JSON"]) # Cosimulation/ only
LinearAlgebra,RandomandStatisticsare Julia standard libraries. PyPlot.jl draws with Python matplotlib through PyCall. - Python 3.9 to 3.12 (the range the Cosimulation ReadMe gives; nothing else in the repository states a version).
- From the repository root:
On macOS or Linux, delete the
python -m venv .venv .venv\Scripts\activate pip install -r requirements.txtesaline first:esadepends onpywin32, which installs only on Windows (andCosimulation/needs Windows anyway). - For
Cosimulation/only, set up PyJulia once:python -c "import julia; julia.install()". - Optional:
pip install gurobipyforData Norms.pyanddata Norms1.py(see the commented line inrequirements.txt). - Edit the hard-coded paths before running:
Cosimulation/main.pylines 15-21 (case and output files) and line 31 (julia_bindir), andCosimulation/PM_solver.pyline 21 (JULIA_BINDIR).Example Optimization Code/Python/Convex Programming/moving_average1.py,moving_average2.pyandmoving_average3.py(thepd.read_csvline) should point toExample Optimization Code/Julia 8 - 16/uy_data.csv.
Julia examples, from the script's own folder (Moving Average.jl reads ./uy_data.csv):
cd "Example Optimization Code\Julia 1 - 7"
julia "SailCo Problem.jl"
Scripts that plot with PyPlot (Hovercraft 1-D.jl, Hovercraft.jl, Moving Average.jl, Polynomial Regression v0.jl, Regression.jl, Structural Optimization.jl, Uncapacitated Facility Location problem.jl) are best run in the Julia REPL so the figures are shown:
julia> cd("Example Optimization Code/Julia 8 - 16")
julia> include("Hovercraft.jl")
Python examples, from the script's own folder:
cd "Example Optimization Code\Python\Linear Programming"
python House.py
Notebook, from the repository root:
jupyter notebook "Optimization Functions/Linear programming/Linear_Programming.ipynb"
Cosimulation, after editing the paths (step 7):
cd Cosimulation
python main.py
- Teaching examples: the data are written in each script, except
Moving Average.jlandmoving_average1-3.py(readuy_data.csv) andportfolio2-4.py(readfolio_mean.csvandfolio_cov.csv, which are not in the repository). Results are printed or plotted.Uncapacitated Facility Location problem.jlalso savessolver_comparison.pdfin the working folder. - Notebook: no input files; prints the solutions of two small LPs.
- Cosimulation: input is a PowerWorld
.pwbcase (not in the repository). Outputs are the same.pwbcase saved in place, a MATPOWER.mfile, a JSON file with the PowerModels solution,gen_map.json, andbranch_data.csv,bus_data.csvandgen_data.csv. All locations are set inmain.py.
Cosimulation/PM_solver.pyrunssolve_ac_pf(an AC power flow, after setting each generator's P and Q limits to its current output), not an OPF, although the Cosimulation ReadMe and the output nameopf_results1.jsonsay OPF. The paths inmain.pyandPM_solver.pyare hard-coded. Details are inCosimulation/ReadMe.md.moving_average1.py,moving_average2.pyandmoving_average3.pyreadC:/Users/Owner/Downloads/uy_data.csv.portfolio2.py,portfolio3.pyandportfolio4.pyneedfolio_mean.csvandfolio_cov.csv, which are not in the repository.Julia 8 - 16/Regression.jlusesuopton line 34 before it is assigned (line 68), so running the whole file stops with anUndefVarError.Julia 1 - 7/Chebyshev Center.jlwrites its constraints asA[i,:]'.*x .+ r.*normalize!(A[i,:]) .<= b[i]. The element-wise product gives a 3 x 3 block of constraints per row, andnormalize!returns a unit vector, not the norm, so the script does not solve the Chebyshev-centre LP.Python/Linear Programming/chebyshev center.pyuses the standard formA[i, :] @ x + r * np.linalg.norm(A[i, :]) <= b[i].Python/Nonconvex and combinatorial models/Cutting Pipe.pydeclares integer variables but keeps GEKKO's default solver setting, IPOPT (SOLVER = 3), which treats integer variables as continuous. Addm.options.SOLVER = 1(APOPT) beforem.solvefor an integer solution. (GEKKO's local Linux build has no IPOPT and falls back to APOPT on its own.)
- GMD-Extended-Team: its folder
Mia/Nathan's code/has byte-identical copies ofCosimulation/convert_to_Matpower_files.pyandCosimulation/gen_mapping.py, and different versions ofmain.py,PM_solver.pyandPW_update.py.
From the git history:
- Philipellon: 79 commits
- EricKellerRE: 19 commits
- Jonathan Snodgrass: 3 commits (2 as "Jonathan Snodgrass", 1 as "jsnodgrass2")
- First commit 2022-08-30; last code commit 2025-12-03.
Optimization Functions/: one commit on 2022-08-30 ("Migrating from TAMU github server"); no changes since. The original README text dates from the same day.Example Optimization Code/: Julia scripts committed 2024-09-16 to 2024-12-11; Python scripts 2024-09-10 to 2024-12-10 (thePython/ReadMe.txtnote was last edited 2025-01-13).Cosimulation/: five commits, all on 2025-12-03. This is the most recent work in the repository.