...
 
Commits (55)
v0.1.0, 22.06.2012 -- Initial release.
v0.1.1, 08.12.2012
* Picos now interfaces GUROBI !
* You can specify an initial solution to *warm-start* mixed integer optimizers.
* Minor bugs with quadratic expressions corrected
* It's possible to return a reference to a constraint added
with add_constraint()
v0.1.2, 10.01.13
bug-fix release, correcting:
* The write_to_file() function for sparse SDPA files.
The function was writing the
coefficients of the lower triangular part
of the constraint matrices
instead of the upper triangle.
* An IndexError occuring with the function
remove_constraint()
v0.1.3, 17.04.13
* geomean() function implemented, to handle inequalities involving
geometric mean and reformulate them as a set of SOCP constraints.
* Some options ['uboundlimit','lboundlimit'] were added to tell
CPLEX to stop the computation as soon as a given value for the
upper bound (or lower bound) is reached.
* The time used by the solver is now stored in the dictionary
returned bz solve().
* It is possible to get the evolution of the lower and upper bounds
over time, by using the option 'boundMonitor'.
* The weak inequalities operator can now be used.
* Minor bugs corrected (access to the duals of fixed variables with CPLEX,
evaluation of constant affine expressions with a zero coefficient appearing
in the dict of linear terms, number of constraints is now updated in remove_constraint() )
v1.0.0, 19.07.13
* Semidefinite Programming Interface for MOSEK 7.0 !!!
* New options ``handleBarVars`` and ``handleConeVars`` to customize how SOCP and SDPs are passed to MOSEK
(When these options are set to ``True`` , PICOS tries to minimize the number of variables of the
MOSEK instance).
* The function dualize() returns the Lagrangian dual of a Problem.
* The option ``solve_via_dual`` allows the user to pass the dual
of a problem to a solver, instead of the primal problem itself. This can yield important speed-up for
certain problems.
* In addition to the geometric mean function picos.geomean(), it is now possible
to pass rational powers of affine expressions (through an overload of the ``**`` operator), trace of
matrix powers with picos.tracepow(), (generalized) p-norms
with picos.norm(), and nth root of a determinant with
picos.detrootn(). These functions automatically reformulate the entered inequalities
as a set of equivalent SOCP or SDP constraints.
* It is now possible to specify variable bounds directly (rather than adding constraints of the type ``x >= 0`` ).
This can be done with the Keywords ``lower`` and ``upper`` of the function add_variable() ,
or by the methods set_lower(), set_upper(), set_sparse_lower(), and set_sparse_upper() of the class Variable.
* It is now more efficient to update a Problem and resolve it. This is done thanks to the attribute ``passed``
of the classes Constraint and Variable ,
that stores which solvers are already aware of a constraint / variable. There is also an
attribute ``obj_passed`` of the class Problem that lists the solver instances
where the objective function has already been passed. The option ``onlyChangeObjective`` has been
deprecated.
\ No newline at end of file
This diff is collapsed.
# file GENERATED by distutils, do NOT edit
README.txt
setup.py
picos/__init__.py
picos/constraint.py
picos/cplex_callbacks.py
picos/expression.py
picos/problem.py
picos/test_picos.py
picos/tools.py
PICOS is a user friendly interface
to several conic and integer programming solvers,
very much like `YALMIP <http://users.isy.liu.se/johanl/yalmip/>`_ under
`MATLAB <http://www.mathworks.com/>`_.
The main motivation for PICOS is to have the possibility to
enter an optimization problem as a *high level model*,
and to be able to solve it with several *different solvers*.
Multidimensional and matrix variables are handled in a natural fashion,
which makes it painless to formulate a SDP or a SOCP.
This is very useful for educational purposes,
and to quickly implement some models and
test their validity on simple examples.
Furthermore, with PICOS you can take advantage of the
python programming language to read and write data,
construct a list of constraints by using python list comprehensions,
take slices of multidimensional variables, etc.
Contributors
============
`Guillaume Sagnol <http://www.zib.de/sagnol>`_
Thanks also to
==============
Bertrand Omont
`Elmar Swarat <http://www.zib.de/swarat>`_
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pyMathProg.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pyMathProg.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/pyMathProg"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pyMathProg"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
solve_via_dual avec cvxopt -- something special to do (finir primalize())
probleme qd solve problems 2 times in a row (test_cutting_plane.py avec mosek6, but only at zib (?))
problem avec duals de gurobi pour probleme dsocp de test_picos.py (faire testSOCP5 ?). Bug gurobi -> min example ?
write_to_file --> scaled vars [mettre ds nom variable ?]
file reader
mps writer
dat-s writer with option to desymmetrize the matrices
Better Exception handling in _retrieve_matrix
quad expression of dimension>1 ?
QP avec cvxopt
doc populate et related properties (number_solutions,value_alt,...)
and options
* pool_size=None (solver default) : maximum number of computed
solutions in the solution pool.
* pool_gap = None (0%) : keeps only the solution
within this gap in the pool
duals avec zibopt ?
documenter dat-sx format ?
sqp method and related options:
* step_sqp=1 : 'first step length for the sequential quadratic programming procedure'
* harmonic_steps=True : step at the ith step of the sqp procedure is step_sqp/i]
no string mode.
generaliser les inplace operators (avoid seelfcopy as much as possible)
lancer script add_google_script
Changer CHANGE file
Creer dist file (python setup.py sdist)
move to /www and change root-index with 3 <meta tags> and $sed -i 's/href="/href="v013\//g' index.html
Register on pypi (python setup.py register, username guillaume.sagnol)
sed -i 's/Picos 0\.1\.0/Picos 0\.1\.1/g' picos/*.py
et change version num dans conf.py and setup.py
This diff is collapsed.
{#
basic/download.html
~~~~~~~~~~~~~~~~~~~
Sphinx sidebar template: download link.
#}
<h3><a href="download.html">{{ _('Download') }}</a></h3>
<ul class="this-page-menu">
<li><a href="{{'dist/PICOS-'+release+'.tar.gz'}}">{{ _('Latest Version ('+release+')') }}</a></li>
</ul>
{#
basic/localtoc2.html
~~~~~~~~~~~~~~~~~~~
Sphinx sidebar template: local table of contents.
:copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
#}
{%- if display_toc %}
<h3><a href="{{ pathto(master_doc) }}">{{ _('Contents of this page') }}</a></h3>
{{ toc }}
{%- endif %}
files = ['index.html','api.html',
'examples.html','constraint.html','expression.html',
'intro.html','tools.html','problem.html',
'download.html','graphs.html','tuto.html','optdes.html']
import os
for f in files:
fi=open('_build/html/'+f,'r')
fitmp=open('_build/html/'+f+'tmp','w')
line = fi.readline()
while '</head>' not in line:
fitmp.write(line)
line = fi.readline()
fitmp.write('\n')
fitmp.write('\n')
fitmp.write(' <script type="text/javascript">\n')
fitmp.write('\n')
fitmp.write(' var _gaq = _gaq || [];\n')
fitmp.write(" _gaq.push(['_setAccount', 'UA-33037163-1']);\n")
fitmp.write(" _gaq.push(['_trackPageview']);\n")
fitmp.write('\n')
fitmp.write(" (function() {\n")
fitmp.write(" var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n")
fitmp.write(" ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n")
fitmp.write(" var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n")
fitmp.write(" })();\n")
fitmp.write('\n')
fitmp.write(" </script>\n")
fitmp.write('\n')
while line:
if 'tar.gz' in line:
vsplit=line.split('tar.gz')
version=vsplit[0].split('PICOS')[1][1:-1]
vsplit=version.split('.')
ocstring=('''onClick="javascript: _gaq.push(['_trackPageview', '/downloads/version'''
+str(vsplit[0]) +str(vsplit[1]) +str(vsplit[2])
+ '''']);"''')
indtar = line.index('tar.gz') + 7
line = line[:indtar]+' '+ocstring+line[indtar:]
fitmp.write(line)
line = fi.readline()
fi.close()
fitmp.close()
os.system('mv _build/html/'+f+'tmp _build/html/'+f)
.. _api:
*******************
The PICOS Reference
*******************
.. toctree::
:maxdepth: 2
problem.rst
tools.rst
expression.rst
constraint.rst
# -*- coding: utf-8 -*-
#
# picos documentation build configuration file, created by
# sphinx-quickstart on Thu Mar 1 10:03:01 2012.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
reload(sys)
sys.setdefaultencoding("UTF-8")
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.doctest',
'sphinx.ext.pngmath',
'matplotlib.sphinxext.only_directives',
'matplotlib.sphinxext.plot_directive',
]
intersphinx_cache_limit = 10 # days to keep the cached inventories
intersphinx_mapping = {
'sphinx': ('http://sphinx.pocoo.org', None),
'python':('http://docs.python.org/2.7',None),
'matplotlib':('http://matplotlib.sourceforge.net', None),
'numpy':('http://docs.scipy.org/doc/numpy',None),
'cvxopt':('http://abel.ee.ucla.edu/cvxopt/userguide',None),
}
todo_include_todos=True
#'cvxopt':('http://abel.ee.ucla.edu/cvxopt/documentation/',None
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'picos'
copyright = u'2012, Guillaume Sagnol'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.0'
# The full version, including alpha/beta/rc tags.
release = '1.0.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
html_short_title = 'PICOS'
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
html_sidebars = {'**': ['globaltoc.html','localtoc2.html','relations.html', 'sourcelink.html', 'download.html', 'searchbox.html']}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'picosdoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'picos.tex', u'picos Documentation',
u'Guillaume Sagnol', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pymathprog', u'picos Documentation',
[u'Guillaume Sagnol'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'picos', u'picos Documentation',
u'Guillaume Sagnol', 'picos', 'python interface to conic optimization solvers.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
def setup(app):
from sphinx.util.texescape import tex_replacements
tex_replacements.append((u'≽',u'\\(\\succeq\\)'))
tex_replacements.append((u'⪴',u'\\(\\succeq\\)'))
tex_replacements.append((u'⪳',u'\\(\\preceq\\)'))
tex_replacements.append((u'≤',u'\\(\\leq\\)'))
tex_replacements.append((u'≥',u'\\(\\geq\\)'))
#copying files
import os
print 'copying pyplots files...'
os.system('cp -v pyplots/*.py _build/html/pyplots/')
print 'done.'
print 'copying dist files...'
os.system('cp -v ../dist/* _build/html/dist')
print 'done.'
\ No newline at end of file
.. _constraint:
==========
Constraint
==========
.. autoclass:: picos.Constraint
:members:
.. autoclass:: picos.GeoMeanConstraint
:members:
:inherited-members: slack
.. autoclass:: picos.NormP_Constraint
:members:
:inherited-members: slack
.. autoclass:: picos.TracePow_Constraint
:members:
:inherited-members: slack
.. autoclass:: picos.DetRootN_Constraint
:members:
:inherited-members: slack
\ No newline at end of file
.. _download:
========
Download
========
The latest version of PICOS can be downloaded here:
`picos-1.0.0 <dist/PICOS-1.0.0.tar.gz>`_
Installation instructions are explained
:ref:`here <requirements>`.
**Older versions**
`picos-0.1.3 <dist/PICOS-0.1.3.tar.gz>`_
`picos-0.1.2 <dist/PICOS-0.1.2.tar.gz>`_
`picos-0.1.1 <dist/PICOS-0.1.1.tar.gz>`_
`picos-0.1.0 <dist/PICOS-0.1.0.tar.gz>`_
\ No newline at end of file
.. _examples:
********
Examples
********
.. toctree::
:maxdepth: 3
optdes.rst
graphs.rst
.. _expression:
==========
Expression
==========
.. autoclass:: picos.Expression
AffinExp
========
.. autoclass:: picos.AffinExp
:members:
Variable
""""""""
.. _variable:
.. autoclass:: picos.Variable
:members:
Norm
====
.. autoclass:: picos.Norm
:members:
QuadExp
=======
.. autoclass:: picos.QuadExp
:members:
LogSumExp
=========
.. autoclass:: picos.LogSumExp
:members:
GeoMeanExp
==========
.. autoclass:: picos.GeoMeanExp
:members:
NormP_Exp
=========
.. autoclass:: picos.NormP_Exp
:members:
TracePow_Exp
============
.. autoclass:: picos.TracePow_Exp
:members:
DetRootN_Exp
============
.. autoclass:: picos.DetRootN_Exp
:members:
\ No newline at end of file
This diff is collapsed.
.. picos documentation master file, created by
sphinx-quickstart on Thu Mar 1 10:03:01 2012.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
.. |br| raw:: html
<br />
PICOS: A Python Interface for Conic Optimization Solvers
========================================================
.. _contents:
**News**
* 19 Jul. 13: **Picos** :ref:`1.0.0 <download>` **Released** |br|
Major Release with following changes:
* Semidefinite Programming Interface for MOSEK 7.0 !!!
* New options ``handleBarVars`` and ``handleConeVars`` to customize how SOCP and SDPs are passed to MOSEK
(When these options are set to ``True`` , PICOS tries to minimize the number of variables of the
MOSEK instance, see the doc in :func:`set_all_options_to_default() <picos.Problem.set_all_options_to_default>`).
* The function :func:`dualize() <picos.Problem.dualize>` returns the Lagrangian dual of a Problem.
* The option ``solve_via_dual`` (documented in
:func:`set_all_options_to_default() <picos.Problem.set_all_options_to_default>` ) allows the user to
pass the dual of a problem to a solver, instead of the primal problem itself.
This can yield important speed-up for certain problems.
* In addition to the geometric mean function :func:`picos.geomean() <picos.tools.geomean>` , it is now possible
to pass rational powers of affine expressions (through an overload of the ``**`` operator), trace of
matrix powers with :func:`picos.tracepow() <picos.tools.tracepow>` , (generalized) p-norms
with :func:`picos.norm() <picos.tools.norm>`, and nth root of a determinant with
:func:`picos.detrootn() <picos.tools.detrootn>`. These functions automatically reformulate the entered inequalities as a set of equivalent SOCP or SDP constraints.
* It is now possible to specify variable bounds directly (rather than adding constraints of the type ``x >= 0`` ).
This can be done with the Keywords ``lower`` and ``upper`` of the function
:func:`add_variable() <picos.Problem.add_variable>` ,
or by the methods :func:`set_lower() <picos.Variable.set_lower>` ,
:func:`set_upper() <picos.Variable.set_upper>` ,
:func:`set_sparse_lower() <picos.Variable.set_sparse_lower>` , and
:func:`set_sparse_upper() <picos.Variable.set_sparse_upper>` of the class :class:`Variable <picos.Variable>`.
* It is now more efficient to update a Problem and resolve it. This is done thanks to the attribute ``passed``
of the classes :class:`Constraint <picos.Constraint>` and :class:`Variable <picos.Variable>` ,
that stores which solvers are already aware of a constraint / variable. There is also an
attribute ``obj_passed`` of the class :class:`Problem <picos.Problem>` , that lists the solver instances
where the objective function has already been passed. The option ``onlyChangeObjective`` has been
deprecated.
* Former changes are listed :ref:`here <changes>`.
**PICOS Documentation contents**
Welcome to the documentation of PICOS.
The latest version can be downloaded :ref:`here <download>`,
and can be installed by following :ref:`these instructions <requirements>`.
This documentation contains a :ref:`tutorial <tuto>` and some :ref:`examples <examples>`,
which should already be enough for a quick start with PICOS. To go deeper,
have a look at the :ref:`picos reference <api>`, which provides information
on every function of PICOS.
.. toctree::
:maxdepth: 2
intro
tuto
examples
api
download
changes
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
This diff is collapsed.
@ECHO OFF
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=_build
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
set I18NSPHINXOPTS=%SPHINXOPTS% .
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^<target^>` where ^<target^> is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. singlehtml to make a single large HTML file
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. devhelp to make HTML files and a Devhelp project
echo. epub to make an epub
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. text to make text files
echo. man to make manual pages
echo. texinfo to make Texinfo files
echo. gettext to make PO message catalogs
echo. changes to make an overview over all changed/added/deprecated items
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
goto end
)
if "%1" == "html" (
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
goto end
)
if "%1" == "singlehtml" (
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\pyMathProg.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\pyMathProg.ghc
goto end
)
if "%1" == "devhelp" (
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished.
goto end
)
if "%1" == "epub" (
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The epub file is in %BUILDDIR%/epub.
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
if errorlevel 1 exit /b 1
echo.
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "text" (
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The text files are in %BUILDDIR%/text.
goto end
)
if "%1" == "man" (
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The manual pages are in %BUILDDIR%/man.
goto end
)
if "%1" == "texinfo" (
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
goto end
)
if "%1" == "gettext" (
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
if errorlevel 1 exit /b 1
echo.
echo.The overview file is in %BUILDDIR%/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
if errorlevel 1 exit /b 1
echo.
echo.Link check complete; look for any errors in the above output ^
or in %BUILDDIR%/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
if errorlevel 1 exit /b 1
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in %BUILDDIR%/doctest/output.txt.
goto end
)
:end
This diff is collapsed.
.. _problem:
=======
Problem
=======
.. autoclass:: picos.Problem
:members:
\ No newline at end of file
import picos as pic
import networkx as nx
#number of nodes
N=20
#Generate a graph with LCF notation (you can change the values below to obtain another graph!)
#We use this deterministic generator in order to have a constant inuput for doctest.
G=nx.LCF_graph(N,[1,3,14],5)
G=nx.DiGraph(G) #edges are bidirected
#generate edge capacities
c={}
for i,e in enumerate(G.edges()):
c[e]=((-2)**i)%17 #an arbitrary sequence of numbers
#---------------#
# MAXCUT SDP #
#---------------#
import cvxopt as cvx
import cvxopt.lapack
import numpy as np
#make G undirected
G=nx.Graph(G)
#allocate weights to the edges
for (i,j) in G.edges():
G[i][j]['weight']=c[i,j]+c[j,i]
maxcut = pic.Problem()
X=maxcut.add_variable('X',(N,N),'symmetric')
#Laplacian of the graph
L=pic.new_param('L',1/4.*nx.laplacian(G))
#ones on the diagonal
maxcut.add_constraint(pic.tools.diag_vect(X)==1)
#X positive semidefinite
maxcut.add_constraint(X>>0)
#objective
maxcut.set_objective('max',L|X)
print maxcut
maxcut.solve(verbose = 0)
#Cholesky factorization
V=X.value
cvxopt.lapack.potrf(V)
for i in range(N):
for j in range(i+1,N):
V[i,j]=0
#random projection algorithm
#Repeat 100 times or until we are within a factor .878 of the SDP optimal value
count=0
obj_sdp=maxcut.obj_value()
obj=0
while (count <100 or obj<.878*obj_sdp):
r=cvx.normal(20,1)
x=cvx.matrix(np.sign(V*r))
o=(x.T*L*x).value[0]
if o>obj:
x_cut=x
obj=o
count+=1
S1=[n for n in range(N) if x[n]<0]
S2=[n for n in range(N) if x[n]>0]
print 'partition of the nodes:'
print 'S1: {0}'.format(S1)
print 'S2: {0}'.format(S2)
cut = [(i,j) for (i,j) in G.edges() if x[i]*x[j]<0]
#display the cut
import pylab
fig=pylab.figure(figsize=(11,8))
#a Layout for which the graph is planar (or use pos=nx.spring_layout(G) with another graph)
pos={
0: (0.07, 0.7),
1: (0.18, 0.78),
2: (0.26, 0.45),
3: (0.27, 0.66),
4: (0.42, 0.79),
5: (0.56, 0.95),
6: (0.6, 0.8),
7: (0.64, 0.65),
8: (0.55, 0.37),
9: (0.65, 0.3),
10:(0.77, 0.46),
11:(0.83, 0.66),
12:(0.90, 0.41),
13:(0.70, 0.1),
14:(0.56, 0.16),
15:(0.40, 0.17),
16:(0.28, 0.05),
17:(0.03, 0.38),
18:(0.01, 0.66),
19: (0, 0.95)}
node_colors=[('g' if n in S1 else 'b') for n in range(N)]
nx.draw_networkx(G,pos,
edgelist=[e for e in G.edges() if e not in cut],
node_color=node_colors)
nx.draw_networkx_edges(G,pos,
edgelist=cut,
edge_color='r')
#hide axis
fig.gca().axes.get_xaxis().set_ticks([])
fig.gca().axes.get_yaxis().set_ticks([])
pylab.show()
\ No newline at end of file
import picos as pic
import networkx as nx
#number of nodes
N=20
#Generate a graph with LCF notation (you can change the values below to obtain another graph!)
#We use this deterministic generator in order to have a constant inuput for doctest.
G=nx.LCF_graph(N,[1,3,14],5)
G=nx.DiGraph(G) #edges are bidirected
#generate edge capacities
c={}
for i,e in enumerate(G.edges()):
c[e]=((-2)**i)%17 #an arbitrary sequence of numbers
#-------------#
# max flow #
#-------------#
maxflow=pic.Problem()
#source and sink nodes
s=16
t=10
#convert the capacities as a picos expression
cc=pic.new_param('c',c)
#flow variable
f={}
for e in G.edges():
f[e]=maxflow.add_variable('f[{0}]'.format(e),1)
#flow value
F=maxflow.add_variable('F',1)
#upper bound on the flows
maxflow.add_list_of_constraints(
[f[e]<cc[e] for e in G.edges()], #list of constraints
[('e',2)], #e is a double index (start and end node of the edges)
'edges' #set the index belongs to
)
#flow conservation
maxflow.add_list_of_constraints(
[ pic.sum([f[p,i] for p in G.predecessors(i)],'p','pred(i)')
== pic.sum([f[i,j] for j in G.successors(i)],'j','succ(i)')
for i in G.nodes() if i not in (s,t)],
'i','nodes-(s,t)')
#source flow at s
maxflow.add_constraint(
pic.sum([f[p,s] for p in G.predecessors(s)],'p','pred(s)') + F
== pic.sum([f[s,j] for j in G.successors(s)],'j','succ(s)')
)
#sink flow at t
maxflow.add_constraint(
pic.sum([f[p,t] for p in G.predecessors(t)],'p','pred(t)')
== pic.sum([f[t,j] for j in G.successors(t)],'j','succ(t)') + F
)
#nonnegativity of the flows
maxflow.add_list_of_constraints(
[f[e]>0 for e in G.edges()], #list of constraints
[('e',2)], #e is a double index (origin and desitnation of the edges)
'edges' #set the index belongs to
)
#objective
maxflow.set_objective('max',F)
print maxflow
maxflow.solve(verbose=0)
#display the graph
import pylab
fig=pylab.figure(figsize=(11,8))
node_colors=['w']*N
node_colors[s]='g' #source is green
node_colors[t]='b' #sink is blue
#a Layout for which the graph is planar (or use pos=nx.spring_layout(G) with another graph)
pos={
0: (0.07, 0.7),
1: (0.18, 0.78),
2: (0.26, 0.45),
3: (0.27, 0.66),
4: (0.42, 0.79),
5: (0.56, 0.95),
6: (0.6, 0.8),
7: (0.64, 0.65),
8: (0.55, 0.37),
9: (0.65, 0.3),
10:(0.77, 0.46),
11:(0.83, 0.66),
12:(0.90, 0.41),
13:(0.70, 0.1),
14:(0.56, 0.16),
15:(0.40, 0.17),
16:(0.28, 0.05),
17:(0.03, 0.38),
18:(0.01, 0.66),
19: (0, 0.95)}
nx.draw_networkx(G,pos,
edgelist=[e for e in G.edges() if f[e].value[0]>0],
node_color=node_colors)
labels={e:'{0}/{1}'.format(f[e],c[e]) for e in G.edges() if f[e].value[0]>0}
#flow label
nx.draw_networkx_edge_labels(G, pos,
edge_labels=labels)
#hide axis
fig.gca().axes.get_xaxis().set_ticks([])
fig.gca().axes.get_yaxis().set_ticks([])
pylab.show()
\ No newline at end of file
import picos as pic
import networkx as nx
#number of nodes
N=20
#Generate a graph with LCF notation (you can change the values below to obtain another graph!)
#We use this deterministic generator in order to have a constant inuput for doctest.
G=nx.LCF_graph(N,[1,3,14],5)
G=nx.DiGraph(G) #edges are bidirected
#generate edge capacities
c={}
for i,e in enumerate(G.edges()):
c[e]=((-2)**i)%17 #an arbitrary sequence of numbers
#-------------#
# min cut #
#-------------#
mincut=pic.Problem()
#source and sink nodes
s=16
t=10
#convert the capacities as a picos expression
cc=pic.new_param('c',c)
#cut variable
d={}
for e in G.edges():
d[e]=mincut.add_variable('d[{0}]'.format(e),1)
#potentials
p=mincut.add_variable('p',N)
#potential inequality
mincut.add_list_of_constraints(
[d[i,j] > p[i]-p[j]
for (i,j) in G.edges()], #list of constraints
['i','j'],'edges') #indices and set they belong to
#one-potential at source
mincut.add_constraint(p[s]==1)
#zero-potential at sink
mincut.add_constraint(p[t]==0)
#nonnegativity
mincut.add_constraint(p>0)
mincut.add_list_of_constraints(
[d[e]>0 for e in G.edges()], #list of constraints
[('e',2)], #e is a double index (origin and desitnation of the edges)
'edges' #set the index belongs to
)
#objective
mincut.set_objective('min',
pic.sum([c[e]*d[e] for e in G.edges()],
[('e',2)],'edges')
)
print mincut
mincut.solve(verbose=0)
cut=[e for e in G.edges() if d[e].value[0]==1]
#display the graph
import pylab
fig=pylab.figure(figsize=(11,8))
node_colors=['w']*N
node_colors[s]='g' #source is green
node_colors[t]='b' #sink is blue
#a Layout for which the graph is planar (or use pos=nx.spring_layout(G) with another graph)
pos={
0: (0.07, 0.7),
1: (0.18, 0.78),
2: (0.26, 0.45),
3: (0.27, 0.66),
4: (0.42, 0.79),
5: (0.56, 0.95),
6: (0.6, 0.8),
7: (0.64, 0.65),
8: (0.55, 0.37),
9: (0.65, 0.3),
10:(0.77, 0.46),
11:(0.83, 0.66),
12:(0.90, 0.41),
13:(0.70, 0.1),
14:(0.56, 0.16),
15:(0.40, 0.17),
16:(0.28, 0.05),
17:(0.03, 0.38),
18:(0.01, 0.66),
19: (0, 0.95)}
#edges (not in the cut)
nx.draw_networkx(G,pos,
edgelist=[e for e in G.edges() if e not in cut],
node_color=node_colors)
#edges of the cut
nx.draw_networkx_edges(G,pos,
edgelist=cut,
edge_color='r')
#hide axis
fig.gca().axes.get_xaxis().set_ticks([])
fig.gca().axes.get_yaxis().set_ticks([])
pylab.show()
\ No newline at end of file