2020-09-02 09:42:51 +02:00
<!-- HTML header for doxygen 1.8.18 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
< html xmlns = "http://www.w3.org/1999/xhtml" >
< head >
< meta http-equiv = "Content-Type" content = "text/xhtml;charset=UTF-8" / >
< meta http-equiv = "X-UA-Compatible" content = "IE=9" / >
2021-09-30 01:18:45 +02:00
< meta name = "generator" content = "Doxygen 1.9.2" / >
2020-09-02 09:42:51 +02:00
< meta name = "viewport" content = "width=device-width, initial-scale=1" / >
< title > OR-Tools: linear_expr.h File Reference< / title >
< link href = "tabs.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "jquery.js" > < / script >
< script type = "text/javascript" src = "dynsections.js" > < / script >
< link href = "navtree.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "resize.js" > < / script >
< script type = "text/javascript" src = "navtreedata.js" > < / script >
< script type = "text/javascript" src = "navtree.js" > < / script >
< link href = "search/search.css" rel = "stylesheet" type = "text/css" / >
< script type = "text/javascript" src = "search/searchdata.js" > < / script >
< script type = "text/javascript" src = "search/search.js" > < / script >
< link href = "doxygen.css" rel = "stylesheet" type = "text/css" / >
< link href = "styleSheet.tmp.css" rel = "stylesheet" type = "text/css" / >
< / head >
< body >
< div id = "top" > <!-- do not remove this div, it is closed by doxygen! -->
< div id = "titlearea" >
< table cellspacing = "0" cellpadding = "0" >
< tbody >
< tr style = "height: 56px;" >
< td id = "projectlogo" > < img alt = "Logo" src = "orLogo.png" / > < / td >
< td id = "projectalign" style = "padding-left: 0.5em;" >
< div id = "projectname" > OR-Tools
2021-09-20 15:57:27 +02:00
  < span id = "projectnumber" > 9.1< / span >
2020-09-02 09:42:51 +02:00
< / div >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
<!-- end header part -->
2021-09-30 01:18:45 +02:00
<!-- Generated by Doxygen 1.9.2 -->
2020-09-02 09:42:51 +02:00
< script type = "text/javascript" >
2021-09-30 01:18:45 +02:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
2020-09-02 09:42:51 +02:00
/* @license-end */
< / script >
< script type = "text/javascript" src = "menudata.js" > < / script >
< script type = "text/javascript" src = "menu.js" > < / script >
< script type = "text/javascript" >
2021-09-30 01:18:45 +02:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
2020-09-02 09:42:51 +02:00
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
2021-09-30 01:18:45 +02:00
/* @license-end */
< / script >
2020-09-02 09:42:51 +02:00
< div id = "main-nav" > < / div >
< / div > <!-- top -->
< div id = "side-nav" class = "ui-resizable side-nav-resizable" >
< div id = "nav-tree" >
< div id = "nav-tree-contents" >
< div id = "nav-sync" class = "sync" > < / div >
< / div >
< / div >
< div id = "splitbar" style = "-moz-user-select:none;"
class="ui-resizable-handle">
< / div >
< / div >
< script type = "text/javascript" >
2021-09-30 01:18:45 +02:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
$(document).ready(function(){initNavTree('linear__expr_8h.html',''); initResizable(); });
2020-09-02 09:42:51 +02:00
/* @license-end */
< / script >
< div id = "doc-content" >
<!-- window showing the filter options -->
< div id = "MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
< / div >
<!-- iframe showing the search results (closed by default) -->
< div id = "MSearchResultsWindow" >
< iframe src = "javascript:void(0)" frameborder = "0"
name="MSearchResults" id="MSearchResults">
< / iframe >
< / div >
< div class = "header" >
< div class = "summary" >
< a href = "#nested-classes" > Classes< / a > |
< a href = "#namespaces" > Namespaces< / a > |
< a href = "#func-members" > Functions< / a > < / div >
2021-09-30 01:18:45 +02:00
< div class = "headertitle" > < div class = "title" > linear_expr.h File Reference< / div > < / div >
2020-09-02 09:42:51 +02:00
< / div > <!-- header -->
< div class = "contents" >
< a name = "details" id = "details" > < / a > < h2 class = "groupheader" > Detailed Description< / h2 >
2021-09-30 01:18:45 +02:00
< div class = "textblock" > < p > This file allows you to write natural code (like a mathematical equation) to model optimization problems with MPSolver. < / p >
< p > It is syntatic sugar on top of the MPSolver API, it provides no additional functionality. Use of these APIs makes it much easier to write code that is both simple and big-O optimal for creating your model, at the cost of some additional constant factor overhead. If model creation is a bottleneck in your problem, consider using the MPSolver API directly instead.< / p >
< p > This file contains two classes:< / p > < ol type = "1" >
2020-09-02 09:42:51 +02:00
< li > LinearExpr: models offset + sum_{i in S} a_i*x_i for decision var x_i,< / li >
< li > LinearRange: models lb < = sum_{i in S} a_i*x_i < = ub, and it provides various operator overloads to build up "LinearExpr"s and then convert them to "LinearRange"s.< / li >
< / ol >
2021-09-30 01:18:45 +02:00
< p > Recommended use (avoids dangerous code):< / p >
< div class = "fragment" > < div class = "line" > MPSolver solver = ...;< / div >
< div class = "line" > < span class = "keyword" > const< / span > LinearExpr x = solver.MakeVar(...); * Note: implicit conversion< / div >
< div class = "line" > < span class = "keyword" > const< / span > LinearExpr y = solver.MakeVar(...);< / div >
< div class = "line" > < span class = "keyword" > const< / span > LinearExpr z = solver.MakeVar(...);< / div >
< div class = "line" > < span class = "keyword" > const< / span > LinearExpr e1 = x + y;< / div >
< div class = "line" > < span class = "keyword" > const< / span > LinearExpr e2 = (e1 + 7.0 + z)/3.0;< / div >
< div class = "line" > < span class = "keyword" > const< / span > LinearRange r = e1 < = e2;< / div >
< div class = "line" > solver.MakeRowConstraint(r);< / div >
< / div > <!-- fragment --> < p > < b > WARNING< / b > , AVOID THIS TRAP:< / p >
< div class = "fragment" > < div class = "line" > MPSolver solver = ...;< / div >
< div class = "line" > MPVariable* x = solver.MakeVar(...);< / div >
< div class = "line" > LinearExpr y = x + 5;< / div >
< / div > <!-- fragment --> < p > In evaluating "x+5" above, x is NOT converted to a LinearExpr before the addition, but rather is treated as a pointer, so x+5 gives a new pointer to garbage memory.< / p >
< p > For this reason, when using LinearExpr, it is best practice to:< / p > < ol type = "1" >
2020-09-02 09:42:51 +02:00
< li > use double literals instead of ints (e.g. "x + 5.0", not "x + 5"),< / li >
< li > Immediately convert all MPVariable* to LinearExpr on creation, and only hold references to the "LinearExpr"s.< / li >
< / ol >
2021-09-30 01:18:45 +02:00
< p > Likewise, the following code is NOT recommended: < / p > < div class = "fragment" > < div class = "line" > MPSolver solver = ...;< / div >
< div class = "line" > MPVariable* x = solver.MakeVar(...);< / div >
< div class = "line" > MPVariable* y = solver.MakeVar(...);< / div >
< div class = "line" > LinearExpr e1 = LinearExpr(x) + y + 5;< / div >
< / div > <!-- fragment --> < p > While it is correct, it violates the natural assumption that the + operator is associative. Thus you are setting a trap for future modifications of the code, as any of the following changes would lead to the above failure mode:< / p >
2020-09-02 09:42:51 +02:00
< ul >
2021-09-30 01:18:45 +02:00
< li > < div class = "fragment" > < div class = "line" > LinearExpr e1 = LinearExpr(x) + (y + 5); < / div >
< / div > <!-- fragment --> < / li >
< li > < div class = "fragment" > < div class = "line" > LinearExpr e1 = y + 5 + LinearExpr(x); < / div >
< / div > <!-- fragment --> < / li >
2020-09-02 09:42:51 +02:00
< / ul >
< p class = "definition" > Definition in file < a class = "el" href = "linear__expr_8h_source.html" > linear_expr.h< / a > .< / p >
< / div >
< p > < a href = "linear__expr_8h_source.html" > Go to the source code of this file.< / a > < / p >
< table class = "memberdecls" >
2021-09-30 01:18:45 +02:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "nested-classes" name = "nested-classes" > < / a >
2020-09-02 09:42:51 +02:00
Classes< / h2 > < / td > < / tr >
2020-10-09 12:00:09 +02:00
< tr class = "memitem:" > < td class = "memItemLeft" align = "right" valign = "top" > class   < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "classoperations__research_1_1_linear_expr.html" > LinearExpr< / a > < / td > < / tr >
< tr class = "memdesc:" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > < a class = "el" href = "classoperations__research_1_1_linear_expr.html" title = "LinearExpr models a quantity that is linear in the decision variables (MPVariable) of an optimization..." > LinearExpr< / a > models a quantity that is linear in the decision variables (< a class = "el" href = "classoperations__research_1_1_m_p_variable.html" title = "The class for variables of a Mathematical Programming (MP) model." > MPVariable< / a > ) of an optimization problem, i.e. < a href = "classoperations__research_1_1_linear_expr.html#details" > More...< / a > < br / > < / td > < / tr >
2020-09-02 09:42:51 +02:00
< tr class = "separator:" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-10-09 12:00:09 +02:00
< tr class = "memitem:" > < td class = "memItemLeft" align = "right" valign = "top" > class   < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "classoperations__research_1_1_linear_range.html" > LinearRange< / a > < / td > < / tr >
< tr class = "memdesc:" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > An expression of the form: < a href = "classoperations__research_1_1_linear_range.html#details" > More...< / a > < br / > < / td > < / tr >
2020-09-02 09:42:51 +02:00
< tr class = "separator:" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
2021-09-30 01:18:45 +02:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "namespaces" name = "namespaces" > < / a >
2020-09-02 09:42:51 +02:00
Namespaces< / h2 > < / td > < / tr >
2021-09-30 01:18:45 +02:00
< tr class = "memitem:namespaceoperations__research" > < td class = "memItemLeft" align = "right" valign = "top" > namespace   < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html" > operations_research< / a > < / td > < / tr >
2021-04-27 23:00:03 +02:00
< tr class = "memdesc:namespaceoperations__research" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Collection of objects used to extend the < a class = "el" href = "classoperations__research_1_1_constraint.html" title = "A constraint is the main modeling object." > Constraint< / a > < a class = "el" href = "classoperations__research_1_1_solver.html" title = "Solver Class." > Solver< / a > library. < br / > < / td > < / tr >
2020-09-02 09:42:51 +02:00
< tr class = "separator:" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
2021-09-30 01:18:45 +02:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "func-members" name = "func-members" > < / a >
2020-09-02 09:42:51 +02:00
Functions< / h2 > < / td > < / tr >
< tr class = "memitem:a4d39af6692e71ee2b0191f0a9d46b764" > < td class = "memItemLeft" align = "right" valign = "top" > std::ostream &   < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#a4d39af6692e71ee2b0191f0a9d46b764" > operator< < < / a > (std::ostream & stream, const LinearExpr & linear_expr)< / td > < / tr >
< tr class = "separator:a4d39af6692e71ee2b0191f0a9d46b764" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a118de93231a6290e4f98ce5d981fd903" > < td class = "memItemLeft" align = "right" valign = "top" > LinearExpr  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#a118de93231a6290e4f98ce5d981fd903" > operator+< / a > (LinearExpr lhs, const LinearExpr & rhs)< / td > < / tr >
< tr class = "separator:a118de93231a6290e4f98ce5d981fd903" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a9a57971e3ced4a836ed66de9dc3b657d" > < td class = "memItemLeft" align = "right" valign = "top" > LinearExpr  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#a9a57971e3ced4a836ed66de9dc3b657d" > operator-< / a > (LinearExpr lhs, const LinearExpr & rhs)< / td > < / tr >
< tr class = "separator:a9a57971e3ced4a836ed66de9dc3b657d" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2021-09-30 01:18:45 +02:00
< tr class = "memitem:a66066138340286e4386bbb3de7eafdf4" > < td class = "memItemLeft" align = "right" valign = "top" > LinearExpr  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#a66066138340286e4386bbb3de7eafdf4" > operator*< / a > (LinearExpr lhs, double rhs)< / td > < / tr >
< tr class = "separator:a66066138340286e4386bbb3de7eafdf4" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-09-02 09:42:51 +02:00
< tr class = "memitem:a81b3f73c470d398ce42791b85964e90f" > < td class = "memItemLeft" align = "right" valign = "top" > LinearExpr  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#a81b3f73c470d398ce42791b85964e90f" > operator/< / a > (LinearExpr lhs, double rhs)< / td > < / tr >
< tr class = "separator:a81b3f73c470d398ce42791b85964e90f" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2021-09-30 01:18:45 +02:00
< tr class = "memitem:a4ad9d128501e5d521839ad16cdc82d39" > < td class = "memItemLeft" align = "right" valign = "top" > LinearExpr  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#a4ad9d128501e5d521839ad16cdc82d39" > operator*< / a > (double lhs, LinearExpr rhs)< / td > < / tr >
< tr class = "separator:a4ad9d128501e5d521839ad16cdc82d39" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-09-02 09:42:51 +02:00
< tr class = "memitem:ad0e6185e1b4809a4edd6cc31ac00d7e2" > < td class = "memItemLeft" align = "right" valign = "top" > LinearRange  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#ad0e6185e1b4809a4edd6cc31ac00d7e2" > operator< =< / a > (const LinearExpr & lhs, const LinearExpr & rhs)< / td > < / tr >
< tr class = "separator:ad0e6185e1b4809a4edd6cc31ac00d7e2" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:ae161405d349af5d521fa0fd25c3b6f83" > < td class = "memItemLeft" align = "right" valign = "top" > LinearRange  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#ae161405d349af5d521fa0fd25c3b6f83" > operator==< / a > (const LinearExpr & lhs, const LinearExpr & rhs)< / td > < / tr >
< tr class = "separator:ae161405d349af5d521fa0fd25c3b6f83" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:ab7cf6c0298d3fa64034fe8d1eff683f6" > < td class = "memItemLeft" align = "right" valign = "top" > LinearRange  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "namespaceoperations__research.html#ab7cf6c0298d3fa64034fe8d1eff683f6" > operator> =< / a > (const LinearExpr & lhs, const LinearExpr & rhs)< / td > < / tr >
< tr class = "separator:ab7cf6c0298d3fa64034fe8d1eff683f6" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table >
< / div > <!-- contents -->
< / div > <!-- doc - content -->
<!-- HTML footer for doxygen 1.8.18 -->
<!-- start footer part -->
< div id = "nav-path" class = "navpath" > <!-- id is needed for treeview function! -->
< ul >
< li class = "navelem" > < a class = "el" href = "dir_a7cc1eeded8f693d0da6c729bc88c45a.html" > ortools< / a > < / li > < li class = "navelem" > < a class = "el" href = "dir_4d3a5a688e4550f3d7725aaa5ab9c27b.html" > linear_solver< / a > < / li > < li class = "navelem" > < a class = "el" href = "linear__expr_8h.html" > linear_expr.h< / a > < / li >
< li class = "footer" > Generated by
< a href = "http://www.doxygen.org/index.html" >
2021-09-30 01:18:45 +02:00
< img class = "footer" src = "doxygen.png" alt = "doxygen" / > < / a > 1.9.2 < / li >
2020-09-02 09:42:51 +02:00
< / ul >
< / div >
< / body >
< / html >