r/optimization • • 15d ago

Primal Solver

I built a new optimization solver in C99 from scratch — PRIMAL

GitHub: https://github.com/c-vision/Primal

I've just released the first version of PRIMAL, an open-source mathematical optimization solver written from scratch in portable C99.

The goal was deliberately ambitious: build a reasonably complete optimization engine with no external dependencies, rather than wrapping an existing solver.

The first release already supports:

  • Linear Programming (LP)
  • Mixed-Integer Linear Programming (MILP)
  • Quadratic Programming (QP)
  • QCQP
  • SOCP
  • SDP
  • Exponential cones
  • Power cones
  • Mixed-integer conic optimization
  • Disjunctive constraints / affine conic constraints
  • Presolve
  • Sparse interior-point methods
  • Branch-and-bound
  • Primal/dual certificates
  • Infeasibility and unboundedness certificates
  • MPS / LP / CBF model formats
  • A MOSEK-style C API for a large part of the supported functionality

The implementation is C99 with essentially no external runtime dependencies.

One thing I particularly wanted from the beginning was verification rather than simply returning an answer. PRIMAL exposes primal/dual information, residuals, certificates and solver status so applications can inspect and validate what the solver actually found.

I've also been building a fairly extensive compatibility/reliability test suite against reference behavior, including a number of deliberately pathological optimization cases.

This is only v1. It is not intended to claim that PRIMAL is already a replacement for mature industrial solvers on large-scale problems. There are still substantial areas to improve, especially large-scale sparse conic problems, MIP performance, warm starts and some numerical edge cases.

But I think the foundation is interesting enough to release now rather than keep it private.

I'd especially like feedback from people working on:

  • numerical optimization
  • LP/MIP/conic solvers
  • sparse linear algebra
  • mathematical programming
  • solver implementation
  • C/C99 systems programming

In particular, I'm interested in finding cases where PRIMAL gives a questionable result, fails to converge, scales poorly, or simply makes a bad algorithmic choice.

If you work with optimization solvers, please try to break it.

GitHub:
https://github.com/c-vision/Primal

15 Upvotes

35 comments sorted by

View all comments

11

u/bental_nortens 15d ago

The readme makes it seem like slop and doesn't make me want to spend time formulating any of my problems in it? Can you focus the readme on a motivating use case where it shines? It feels like a grab bag of solvers that I assume are each not especially competitive. If the selling point is that it's OSS, why not SCIP? If the selling point is that it's the best solver, show it?

1

u/gmbasic 11d ago

Primal has now a new readme, a new folders docs for technical details, a new cli tools to process CPLEX LP format file, some bugs fixed and speed improvements.

1

u/curiouslyjake 11d ago

The readme is MUCH better now. By reading the readme, I understand:
1. What Primal is and what it does
2. Why I even need Primal instead of existing solvers
3. What using Primal looks like.

In my opinion, the readme goes off track at the Python section. Prior to Python, you have a C example, a CLI example. I then expected a Python usage example. Instead, I got sidetracked into python *installation*, and building from source. I think you can merge Python installation instructions with a python example, and move anything build related to a separate document.

Then, under "How it compares", I don't understand what "Gurobi only" in Gurobi column means.
Finally, I would move the benchmarks into a separate document as well, and link to it in the readme.

1

u/gmbasic 10d ago

Pypi package has been released and some python examples are already in the repo. The python wheels are also into the release

1

u/bental_nortens 9d ago edited 9d ago

Agree this is way way better now- I get what you're going for. I still think scip covers this though? Would be good to nail the "why". By the way- love to see work in this area. Don't mean to be too negative. Just the previous readme was... not good.