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.5.4 or higher (tested with 1.5.4, 1.6.7, and 1.7.x)

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 the Apache License 2.0 - 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.0.tar.gz (827.0 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.0-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dccp-1.1.0.tar.gz
  • Upload date:
  • Size: 827.0 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.0.tar.gz
Algorithm Hash digest
SHA256 04fd80337a03fb2a2a3989a6ba0314e1df2b857be5324d57b7a7729e480ca4bb
MD5 9e368501302da1374229a5b45d898529
BLAKE2b-256 bcdbd2c8c3dd7b057a1cf637aaaebe44fa6c5ee40921226324e91c3ed3a58db0

See more details on using hashes here.

Provenance

The following attestation bundles were made for dccp-1.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: dccp-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.4 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ba7f6bfe84fcdc922e3a2c50672d59245a7c2c995bc81258c15a097d9e67633d
MD5 46ba69e99bd1527b160a246f75b2e2c6
BLAKE2b-256 2ef6720bf79e8a4a27c453e0c180cbd1a735e5cd0ff7d3d37b7def799eec076d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dccp-1.1.0-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