Skip to main content

A CVXPY extension for difference of convex programs.

Project description

DCCP

build docs codecov license pypi

DCCP package provides an organized heuristic for convex-concave programming. It tries to solve nonconvex problems where every function in the objective and the constraints has any known curvature according to the rules of disciplined convex programming (DCP). For instance, DCCP can be used to maximize a convex function. The full details of our approach are discussed in the associated paper. DCCP is built on top of CVXPY, a domain-specific language for convex optimization embedded in Python.

Installation

Requirements:

  • Python 3.11 or higher
  • CVXPY 1.9.0 or higher

You can install the latest DCCP package via pip:

pip install dccp

To install the development version, clone this repository and install in development mode:

git clone https://github.com/cvxgrp/dccp.git
cd dccp
pip install -e .

Note: DCCP now includes full type hints and passes strict type checking with pyright.

DCCP Rules

A problem satisfies the rules of disciplined convex-concave programming (DCCP) if it has the form

$$ \begin{align} \text{minimize/maximize} \quad & o(x) \ \text{subject to} \quad & l_i(x) \sim r_i(x), \quad i=1,\ldots,m, \end{align} $$

where $o$ (the objective), $l_i$ (left-hand sides), and $r_i$ (right-hand sides) are expressions (functions in the variable $x$) with curvature known from the DCP composition rules, and $\sim$ denotes one of the relational operators $==$, $<=$, or $>=$.

In a disciplined convex program, the curvatures of $o$, $l_i$, and $r_i$ are restricted to ensure that the problem is convex. For example, if the objective is $\text{maximize} , o(x)$, then $o$ must be concave according to the DCP composition rules. In a disciplined convex-concave program, by contrast, the objective and right and left-hand sides of the constraints can have any curvature, so long as all expressions satisfy the DCP composition rules.

The variables, parameters, and constants in DCCP should be real numbers. Problems containing complex numbers may not be supported by DCCP.

Example

The following code uses DCCP to approximately solve a simple nonconvex problem.

import cvxpy as cp
import dccp

x = cp.Variable(2)
y = cp.Variable(2)
myprob = cp.Problem(cp.Maximize(cp.norm(x - y, 2)), [0 <= x, x <= 1, 0 <= y, y <= 1])
print("problem is DCP:", myprob.is_dcp())   # False
print("problem is DCCP:", dccp.is_dccp(myprob))  # True
result = myprob.solve(method='dccp', seed=3)
print("x =", x.value.round(3))
print("y =", y.value.round(3))
print("cost value =", result)

The output of the above code is as follows.

problem is DCP: False
problem is DCCP: True
x = [1. 0.]
y = [0.  1.]
cost value = 1.4142135623730951

The solutions obtained by DCCP can depend on the initial point of the CCP algorithm. The algorithm starts from the values of any variables that are already specified; for any that are not specified, random values are used. You can specify an initial value manually by setting the value field of the variable. For example, the following code runs the CCP algorithm with the specified initial values for x and y:

import numpy

x.value = numpy.array([1, 2])
y.value = numpy.array([-1, 1])
result = myprob.solve(method='dccp')

By first clearing the variable values using x.value = None and y.value = None, the CCP algorithm will use random initial values.

Setting the parameter k_ccp specifies the number of times that the CCP algorithm runs, starting from random initial values for all variables. The best solution found is returned.

For all available parameters, see the documentation.

License

This project is licensed under GPLv3 - see the LICENSE file for details.

Citation

If you wish to cite DCCP, please cite the DCCP papers listed in our citation guide or copy the text below.

@article{shen2016disciplined,
    author       = {Xinyue Shen and Steven Diamond and Yuantao Gu and Stephen Boyd},
    title        = {Disciplined convex-concave programming},
    journal      = {2016 IEEE 55th Conference on Decision and Control (CDC)},
    pages        = {1009--1014},
    year         = {2016},
    url          = {https://stanford.edu/~boyd/papers/dccp.html},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dccp-1.1.1.tar.gz (827.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dccp-1.1.1-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file dccp-1.1.1.tar.gz.

File metadata

  • Download URL: dccp-1.1.1.tar.gz
  • Upload date:
  • Size: 827.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dccp-1.1.1.tar.gz
Algorithm Hash digest
SHA256 0b1a1346bb38c38b5a0c079238395f184558e48aaada5ef57ac80c2168c5eb83
MD5 05cb9deb292ef76ceb14632236be56e3
BLAKE2b-256 71d9fc583c545a6c77e294dd7bb19164cbffdd911ebb0d2a02bb2e06ecafe08a

See more details on using hashes here.

Provenance

The following attestation bundles were made for dccp-1.1.1.tar.gz:

Publisher: build.yml on cvxgrp/dccp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dccp-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: dccp-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for dccp-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4735c4106b017f3cfe3fb33d79cdcf52b3ef8501d57d844a7354e6c898c38c95
MD5 22fbcec6fd4130cccef4591699c66542
BLAKE2b-256 c95ce4efb07b3e914c4ed42db83a01e6633d1deee0a1e8ff1f9231eceea1b9eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for dccp-1.1.1-py3-none-any.whl:

Publisher: build.yml on cvxgrp/dccp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page