当前位置:网站首页>Gurobi——GRBLinExpr
Gurobi——GRBLinExpr
2022-07-27 16:40:00 【An audience who doesn't understand music】
List of articles
- GRBLinExpr
- GRBLinExpr()
- GRBLinExpr::addTerms()
- GRBLinExpr::clear()
- GRBLinExpr::getConstant()
- GRBLinExpr::getCoeff()
- GRBLinExpr::getValue()
- GRBLinExpr::getVar()
- GRBLinExpr::operator=
- GRBLinExpr::operator+
- GRBLinExpr::operator-
- GRBLinExpr::operator+=
- GRBLinExpr::operator-=
- GRBLinExpr::operator*=
- GRBLinExpr::remove()
- GRBLinExpr::size()
GRBLinExpr
Gurobi Linear expression object . A linear expression consists of a constant term and a list of coefficient variable pairs that capture the linear term . Linear expressions are used to construct constraints . They are usually short-lived temporary objects .
GRBLinExpr Class is an abstract base class GRBExpr Subclasses of .
You usually use overloaded operators to build linear expressions . for example , If x yes GRBVar object , be x + 1 yes GRBLinExpr object . Expressions can consist of constants ( for example expr = 0)、 Variable ( for example expr = 1 * x + 2 * y) Or other expressions ( for example expr2 = 2 * expr1 + x or expr3 = expr1 + 2 * expr2). You can also modify existing expressions ( for example expr += x or expr2 -= expr1).
Another option for building expressions is to use addTerms Method , It adds a new set of terms at a time . You can also use remove Remove the term... From the expression .
Please note that , The cost of building expressions depends largely on the method you use . Although you can usually ignore this problem when building small expressions , But there are some efficiency issues when building large expressions :
- You should avoid using... In loops expr = expr + x. This will result in a runtime with a quadratic number of items in the expression .
- Use expr += x( or expr -= x) Than expr = expr + x More effective . Through the loop += Statement to build large expressions is quite effective , But it's not the most effective way .
- The most effective way to build large expressions is to addTerms Make a call .
To add linear constraints to your model , You usually build one or two linear expression objects (expr1 and expr2), Then use overloaded comparison operators to build GRBModel::addConstr Parameters of . Take a few examples :
After adding constraints to the model , Subsequent changes to the expression object used to build the constraint will not change the constraint ( You will use... For this GRBModel::chgCoeff).
have access to getVar、getCoeff and getConstant Method to query each item in a linear expression . You can use size Method to query the number of items in the expression .
Please note that , A linear expression may contain multiple terms involving the same variable . These duplicates are merged when creating constraints from expressions , But they may be visible when examining individual items in an expression ( for example , Use getVar when ).
GRBLinExpr()
Linear expression constructor . Create a constant expression or an expression with a term .
GRBLinExpr GRBLinExpr (double constant=0.0 )
Create a constant linear expression .
| Parameters | Detailed explanation |
|---|---|
| constant (optional) | The constant value of the expression . |
| Return value | A constant expression object . |
GRBLinExpr GRBLinExpr(GRBVar var, double coeff=1.0 )
Create an expression with one word .
| Parameters | Detailed explanation |
|---|---|
| var | Variables of expression terms . |
| coeff( Optional ) | The coefficient of the expression term . |
| Return value | An expression object that contains a linear term . |
GRBLinExpr::addTerms()
Add a new item to the linear expression .
void addTerms (const double* coeffs,
const GRBVar* vars,
int count)
| Parameters | Detailed explanation |
|---|---|
| coeffs | The coefficient of the new term . |
| vars | Variables of the new term . |
| count | Number of items to add to the expression . |
GRBLinExpr::clear()
Set linear expression to 0.
You should use overloaded expr = 0. clear Method is mainly to keep consistent with our interface to non overloaded language .
void clear()
GRBLinExpr::getConstant()
Retrieve constant terms from linear expressions .
double getConstant ( )
Return value : Constants from expressions .
GRBLinExpr::getCoeff()
Retrieve coefficients from a single item of an expression .
double getCoeff ( int i )
| Parameters | Detailed explanation |
|---|---|
| i | Coefficient of interest index . |
| Return value | Index in expression i The coefficient of the term at . |
GRBLinExpr::getValue()
Calculate the value of the linear expression of the current solution .
double getValue()
Return value : The value of the expression for the current solution .
GRBLinExpr::getVar()
Retrieves a variable object from a single item in an expression .
GRBVar getVar ( int i )
| Parameters | Detailed explanation |
|---|---|
| i | Index of items of interest . |
| Return value | Index in expression i Variables in terms . |
GRBLinExpr::operator=
Set one expression equal to another .
GRBLinExpr operator=(const GRBLinExpr& rhs)
| Parameters | Detailed explanation |
|---|---|
| rhs | Source expression . |
| Return value | New expression object . |
GRBLinExpr::operator+
Add one expression to another , Generate the result expression .
GRBLinExpr operator+(const GRBLinExpr& rhs)
| Parameters | Detailed explanation |
|---|---|
| rhs | The expression to add . |
| Return value | Expression object , It is equal to the sum of the call expression and the parameter expression . |
GRBLinExpr::operator-
Subtract an expression from another expression , Produce a result expression .
GRBLinExpr operator-(const GRBLinExpr& rhs)
| Parameters | Detailed explanation |
|---|---|
| rhs | The expression to subtract . |
| Return value | Expression object , It is equal to the call expression minus the parameter expression . |
GRBLinExpr::operator+=
Add an expression to the call expression .
void operator+=(const GRBLinExpr& expr)
| Parameters | Detailed explanation |
|---|---|
| expr | The expression to add . |
| Return value | nothing . |
GRBLinExpr::operator-=
Subtract an expression from an expression call .
void operator-= ( const GRBLinExpr& expr )
| Parameters | Detailed explanation |
|---|---|
| expr | The expression to subtract . |
| Return value | nothing . |
GRBLinExpr::operator*=
Multiply the call expression by a constant .
void operator*=(double multiplier)
| Parameters | Detailed explanation |
|---|---|
| multiplier | Constant multiplier . |
| Return value | nothing . |
GRBLinExpr::remove()
Delete an item from a linear expression .
void remove(int i)
Delete stored in the expression index i Item at .
| Parameters | Detailed explanation |
|---|---|
| i | Index of the entry to be deleted . |
boolean remove(GRBVar var)
Remove variables from the expression var All associated items .
| Parameters | Detailed explanation |
|---|---|
| var | The variable whose item should be deleted . |
| Return value | If the variable appears in a linear expression ( And has been deleted ), Then return to true. |
GRBLinExpr::size()
Retrieves the number of items in a linear expression ( Excluding constants ).
unsigned int size()
Return value : The number of items in the expression .
边栏推荐
- string数字类型转换为千分位
- const小结
- Google Chrome reversecaptcha ad blocking
- The 4.3 billion euro cash acquisition of OSRAM failed! AMS said it would continue to acquire
- DRF learning notes (II): Data deserialization
- 知网、万方数据库免费下载论文------比连接学校内网速度快数倍不止(有的学校万方数据库不支持下载)
- After the cubemx is reconfigured, the generated code cannot be opened successfully with IAR
- solidwork装配体导入到Adams中出现多个Part重名和Part丢失的情况处理
- The difference between select/poll/epoll
- Use of arrow function
猜你喜欢

The 31st --- the 52nd

Collection! 0 basic open source data visualization platform flyfish large screen development guide

OpenCV(二)——图像基本处理

Insert pictures in word to maintain high DPI method

Mysql5.7 master-slave hot standby settings on CentOS

201403-1

收藏!0基础开源数据可视化平台FlyFish大屏开发指南

Is low code the future of development? On low code platform

DRF use: get request to get data (small example)

Exe program encryption lock
随机推荐
Insert pictures in word to maintain high DPI method
【论文阅读】Single- and Cross-Modality Near Duplicate Image PairsDetection via Spatial Transformer Compar
kubesphere多节点安装出错
Flume incrementally collects MySQL data to Kafka
OpenCV(二)——图像基本处理
知网、万方数据库免费下载论文------比连接学校内网速度快数倍不止(有的学校万方数据库不支持下载)
Leetcode25 question: turn the linked list in a group of K -- detailed explanation of the difficult questions of the linked list
The difference and use between get request and post request
Example of the task submitted by the Flink packer
Jupyter creates a virtual environment and installs pytorch (GPU)
OpenCV(五)——运动目标识别
CCF-201312-1
jupyter 创建虚拟环境并安装pytorch(gpu)
Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)
Codeforces Round #100 E. New Year Garland & 2021 CCPC Subpermutation
【论文阅读】A CNN-Transformer Hybrid Approach for CropClassification Using MultitemporalMultisensor Images
Simulation generate report
After the cubemx is reconfigured, the generated code cannot be opened successfully with IAR
Const summary
The 21st - -- the 30th time