doc/ 0000755 0001750 0001750 00000000000 11247522375 010277 5 ustar rene rene doc/get_working_objective.htm 0000644 0001750 0001750 00000006077 10237215410 015357 0 ustar rene rene
get_working_objectiveReturns the value of the objective function. REAL get_working_objective(lprec *lp); Return Value get_working_objective returns the current value of the objective while
solving the model. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI Remarks The get_working_objective function returns the current value of the
objective while solving the model. Example
See Also make_lp, copy_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, get_working_objective, is_feasible, get_variables, get_ptr_variables, get_constraints, get_ptr_constraints, get_constr_value, get_primal_solution, get_ptr_primal_solution, get_var_primalresult, get_sensitivity_rhs, get_ptr_sensitivity_rhs, get_dual_solution, get_ptr_dual_solution, get_var_dualresult, get_sensitivity_obj, get_ptr_sensitivity_obj, get_sensitivity_objex, get_ptr_sensitivity_objex |
Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the library's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. <signature of Ty Coon>, 1 April 1990 Ty Coon, President of Vice That's all there is to it!doc/set_sense.htm 0000644 0001750 0001750 00000004531 10237176664 013010 0 ustar rene rene
set_senseSet objective function sense. void set_sense(lprec *lp, unsigned char maximize); Return Value set_sense has no return value. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI maximize Set sense to minimize (FALSE) or maximize (TRUE). Remarks The set_sense function sets the objective sense. The default of lp_solve is to minimize, except for read_lp, read_LP where the default is to maximize. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_minim, set_maxim, is_maxim |
write_basisWrites current basis to a file. unsigned char write_basis(lprec *lp, char *filename); Return Value Returns TRUE if basis could be written to filename and FALSE if not. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI filename Filename to write the basis to. Remarks
The write_basis function writes the current basis to filename. The basis in the file is written in MPS bas file format. When filename is NULL, then output is written to output set by set_outputstream, set_outputfile. By default this is stdout. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, get_basis, set_basis, default_basis, read_basis, guess_basis, get_basiscrash, set_basiscrash |
make_lpCreate and initialise a new lprec structure. lprec *make_lp(int rows, int columns); Return Value
Returns a pointer to a new lprec structure. This must be provided to almost all
lp_solve functions. Parameters rows Initial number of rows. Can be 0 as new rows can be added via add_constraint, add_constraintex, str_add_constraint columns Initial number of columns. Can be 0 as new columns can be added via add_column, add_columnex, str_add_column Remarks
The make_lp function constructs a new LP. Sets all variables to initial
values. Example
See Also copy_lp, delete_lp, free_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, resize_lp |
We shall illustrate the method of linear programming by means of a simple example, giving a combination graphical/numerical solution, and then solve the problem in lpsolve in different ways. This via ASCII files and from different programming languages.
Suppose a farmer has 75 acres on which to plant two crops: wheat and barley. To produce these crops, it costs the farmer (for seed, fertilizer, etc.) $120 per acre for the wheat and $210 per acre for the barley.The farmer has $15000 available for expenses. But after the harvest, the farmer must store the crops while awaiting favourable market conditions. The farmer has storage space for 4000 bushels.Each acre yields an average of 110 bushels of wheat or 30 bushels of barley. If the net profit per bushel of wheat (after all expenses have been subtracted) is $1.30 and for barley is $2.00, how should the farmer plant the 75 acres to maximize profit?
We begin by formulating the problem mathematically. First we express the objective, that is the profit, and the constraints algebraically, then we graph them, and lastly we arrive at the solution by graphical inspection and a minor arithmetic calculation.
Let x denote the number of acres allotted to wheat and y the number of acres allotted to barley. Then the expression to be maximized, that is the profit, is clearly
P = (110)(1.30)x + (30)(2.00)y = 143x + 60y.
There are three constraint inequalities, specified by the limits on expenses, storage and acreage. They are respectively:
120x + 210y <= 15000
110x + 30y <= 4000
x + y <= 75
Strictly speaking there are two more constraint inequalities forced by the fact that the farmer cannot plant a negative number of acres, namely:
x >= 0,y >= 0.
Next we graph the regions specified by the constraints. The last two say that we only need to consider the first quadrant in the x-y plane. Here's a graph delineating the triangular region in the first quadrant determined by the first inequality.
Now let's put in the other two constraint inequalities.
The black area is the solution space that holds valid solutions. This means that any point in this area fulfils the constraints.
Now let's superimpose on top of this picture a contour plot of the objective function P.
The lines give a picture of the objective function. All solutions that intersect with the black area are valid solutions, meaning that this result also fulfils the set constraints. The more the lines go to the right, the higher the objective value is. The optimal solution or best objective is a line that is still in the black area, but with an as large as possible value.
It seems apparent that the maximum value of P will occur on the level curve (that is, level
line) that passes through the vertex of the polygon that lies near (22,53).
It is the intersection of x + y = 75 and 110*x + 30*y = 4000
This is a corner point of the diagram. This is not a coincidence. The simplex algorithm, which is used
by lpsolve, starts from a theorem that the optimal solution is such a corner point.
In fact we can compute the result:
x + y = 75 (1) 110*x + 30*y = 4000 (2)
From (1), y can be expressed in function of x:
y = 75 - x (3)
This equation can be substituted in (2):
110*x + 30*(75 - x) = 4000
Or:
80*x = 1750
Or:
x = 21.875
From (3), y can be derived:
y = 75 - 21.875 = 53.125
The acreage that results in the maximum profit is 21.875 for wheat and 53.125 for barley. In that case the profit is:
P = 143*x + 60*y
Or:
P = 143*21.875 + 60*53.125 = 6326.625That is, $6315.625.
Now, lpsolve comes into the picture to solve this linear programming problem more generally.
First let us show this problem in its mathematical format:
max(143x + 60y) s.t. 120x + 210y <= 15000 110x + 30y <= 4000 x + y <= 75 x >= 0 y >= 0
There are several ways to model a linear problem via lpsolve:
There exist a lot of formats to model an lp problem into. Almost each solver has its format on its own.
The MPS format is supported by most lp solvers and thus very universal. The model is provided to the solver via an ASCII file. This format is very old and difficult to read by humans. See MPS file format for a complete description about the format. This problem is formulated as follows in MPS format:
* model.mps NAME ROWS N R0 L R1 L R2 L R3 COLUMNS x R0 143.00000000 R1 120.00000000 x R2 110.00000000 R3 1.0000000000 y R0 60.00000000 R1 210.00000000 y R2 30.000000000 R3 1.0000000000 RHS RHS R1 15000.000000 R2 4000.0000000 RHS R3 75.000000000 ENDATA
Save this as ASCII file with name model.mps
To read this format in lpsolve, the API functions read_mps, read_freemps, read_MPS, read_freeMPS can be used. The lpsolve distribution comes with two applications that use this API call to read a model:
To read this MPS model via the lp_solve command line program and calculate the solution, enter the following command:
lp_solve -max -mps model.mps
This gives:
Value of objective function: 6315.63 Actual values of the variables: x 21.875 y 53.125
The lp_solve program has a lot of options that can be set. See lp_solve command
Under Windows, there is also a graphical IDE that can read an MPS file. See LPSolve IDE for more information.
The lp format is the native lpsolve format to provide LP models via an ASCII file to the solver. It is very readable and its syntax is very similar to the Mathematical formulation. See LP file format for a complete description about the format. This model is formulated as follows in lp-format:
/* model.lp */ max: 143 x + 60 y; 120 x + 210 y <= 15000; 110 x + 30 y <= 4000; x + y <= 75;
Save this as ASCII file with name model.lp
To read this format in lpsolve, the API functions read_lp, read_LP can be used. The lpsolve distribution comes with two applications that use this API call to read a model:
To read this lp model via the lp_solve command line program and calculate the solution, enter the following command:
lp_solve model.lp
This gives:
Value of objective function: 6315.63 Actual values of the variables: x 21.875 y 53.125
The lp_solve program has a lot of options that can be set. See lp_solve command
Under Windows, there is also a graphical IDE that can read an lp-file. See LPSolve IDE for more information.
The CPLEX lp format is another format to provide LP models via an ASCII file to the solver. It is very readable and its syntax is very similar to the Mathematical formulation. It is a format used by the CPLEX solver. See CPLEX lp files for a complete description about the format. This model is formulated as follows in CPLEX lp format:
\* model.lpt *\ Maximize +143 x +60 y Subject To +120 x +210 y <= 15000 +110 x +30 y <= 4000 +x +y <= 75 End
Save this as ASCII file with name model.lpt
lpsolve doesn't has an API call to read/write this format. However, the lpsolve distribution has an XLI that can do this. See External Language Interfaces for a description about XLIs. This uses the API call read_XLI. The xli to read/write this format is xli_CPLEX. The lpsolve distribution comes with two applications that use this API call to read a model:
To read this CPLEX lp model via the lp_solve command line program and calculate the solution, enter the following command:
lp_solve -rxli xli_CPLEX model.lpt
This gives:
Value of objective function: 6315.63 Actual values of the variables: x 21.875 y 53.125
The lp_solve program has a lot of options that can be set. See lp_solve command
Under Windows, there is also a graphical IDE that can read a CPLEX lp file via an XLI. See LPSolve IDE for more information.
The LINDO FILE format is another format to provide LP models via an ASCII file to the solver. It is very readable and its syntax is very similar to the Mathematical formulation. It is a format used by the LINDO solver. See LINDO lp files for a complete description about the format. This model is formulated as follows in LINDO FILE format:
! model.lnd MAXIMIZE +143 x +60 y SUBJECT TO +120 x +210 y <= 15000 +110 x +30 y <= 4000 +x +y <= 75 END
Save this as ASCII file with name model.lpt
lpsolve doesn't has an API call to read/write this format. However, the lpsolve distribution has an XLI that can do this. See External Language Interfaces for a description about XLIs. This uses the API call read_XLI. The xli to read/write this format is xli_LINDO. The lpsolve distribution comes with two applications that use this API call to read a model:
To read this LINDO lp model via the lp_solve command line program and calculate the solution, enter the following command:
lp_solve -rxli xli_LINDO model.lnd
This gives:
Value of objective function: 6315.63 Actual values of the variables: x 21.875 y 53.125
The lp_solve program has a lot of options that can be set. See lp_solve command
Under Windows, there is also a graphical IDE that can read a LINDO lp file via an XLI. See LPSolve IDE for more information.
The GNU MathProg format is another format to provide LP models via an ASCII file to the solver. It is very readable and its syntax is very similar to the Mathematical formulation. It is a format used by the GLPK solver and a subset of AMPL. It has also the possibility to use loops. See Modeling Language GNU MathProg This model is formulated as follows in GNU MathProg format:
/* model.mod */ var x >= 0; var y >= 0; maximize obj: +143*x +60*y; R1: +120*x +210*y <= 15000; R2: +110*x +30*y <= 4000; R3: +x +y <= 75;
Save this as ASCII file with name model.mod
lpsolve doesn't has an API call to read/write this format. However, the lp_solve distribution has an XLI that can do this. See External Language Interfaces for a description about XLIs. This uses the API call read_XLI. The xli to read/write this format is xli_MathProg. The lpsolve distribution comes with two applications that use this API call to read a model:
To read this GNU MathProg model via the lp_solve command line program and calculate the solution, enter the following command:
lp_solve -rxli xli_MathProg model.mod
This gives:
Value of objective function: 6315.63 Actual values of the variables: x 21.875 y 53.125
The lp_solve program has a lot of options that can be set. See lp_solve command
Under Windows, there is also a graphical IDE that can read a GNU MathProg file via an XLI. See LPSolve IDE for more information.
The LPFML XML format is another format to provide LP models via an ASCII file to the solver. This format is very recent and uses XML layout. It is not very readable by us, but because of the XML structure very flexible. See LPFML: A W3C XML Schema for Linear Programming for more information. This model is formulated as follows in LPFML XML format:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <mathProgram xmlns="http://FML/lpfml.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://FML/lpfml.xsd lpfml.xsd"> <linearProgramDescription> <source></source> <maxOrMin>max</maxOrMin> <numberRows>3</numberRows> <numberVars>2</numberVars> </linearProgramDescription> <linearProgramData> <rows> <row rowName="R1" rowUB="15000"/> <row rowName="R2" rowUB="4000"/> <row rowName="R3" rowUB="75"/> </rows> <columns> <col colName="x" colType="C" objVal="143"/> <col colName="y" colType="C" objVal="60"/> </columns> <amatrix> <sparseMatrix> <pntANonz> <el>3</el> <el>6</el> </pntANonz> <rowIdx> <el>0</el> <el>1</el> <el>2</el> <el>0</el> <el>1</el> <el>2</el> </rowIdx> <nonz> <el>120</el> <el>110</el> <el>1</el> <el>210</el> <el>30</el> <el>1</el> </nonz> </sparseMatrix> </amatrix> </linearProgramData> </mathProgram>
Save this as ASCII file with name model.xml
lpsolve doesn't has an API call to read/write this format. However, the lp_solve distribution has an XLI that can do this. See External Language Interfaces for a description about XLIs. This uses the API call read_XLI. The xli to read/write this format is xli_LPFML. The lpsolve distribution comes with two applications that use this API call to read a model:
To read this LPFML XML model via the lp_solve command line program and calculate the solution, enter the following command:
lp_solve -rxli xli_LPFML model.xml
This gives:
Value of objective function: 6315.63 Actual values of the variables: x 21.875 y 53.125
The lp_solve program has a lot of options that can be set. See lp_solve command
Under Windows, there is also a graphical IDE that can read a LPFML XML file via an XLI. See LPSolve IDE for more information.
There are several commercial and free Mathematical programming applications out there which can be used to solve lp problems. An lpsolve driver is made for several of them:
In several cases it is required that the solver is called from within the programming language in which an application is build. All the data is in memory and no files are created to provide data to the solver. lpsolve has a very rich, yet easy, API to do this. See lp_solve API reference for an overview of the API. lpsolve is a library of API routines. This library is called from the programming language. See Calling the lpsolve API from your application for more information. Above example is now formulated in several programming languages:
The example model can be formulated as follows in C:
/* demo.c */ #include "lp_lib.h" int demo() { lprec *lp; int Ncol, *colno = NULL, j, ret = 0; REAL *row = NULL; /* We will build the model row by row So we start with creating a model with 0 rows and 2 columns */ Ncol = 2; /* there are two variables in the model */ lp = make_lp(0, Ncol); if(lp == NULL) ret = 1; /* couldn't construct a new model... */ if(ret == 0) { /* let us name our variables. Not required, but can be useful for debugging */ set_col_name(lp, 1, "x"); set_col_name(lp, 2, "y"); /* create space large enough for one row */ colno = (int *) malloc(Ncol * sizeof(*colno)); row = (REAL *) malloc(Ncol * sizeof(*row)); if((colno == NULL) || (row == NULL)) ret = 2; } if(ret == 0) { set_add_rowmode(lp, TRUE); /* makes building the model faster if it is done rows by row */ /* construct first row (120 x + 210 y <= 15000) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 120; colno[j] = 2; /* second column */ row[j++] = 210; /* add the row to lpsolve */ if(!add_constraintex(lp, j, row, colno, LE, 15000)) ret = 3; } if(ret == 0) { /* construct second row (110 x + 30 y <= 4000) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 110; colno[j] = 2; /* second column */ row[j++] = 30; /* add the row to lpsolve */ if(!add_constraintex(lp, j, row, colno, LE, 4000)) ret = 3; } if(ret == 0) { /* construct third row (x + y <= 75) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 1; colno[j] = 2; /* second column */ row[j++] = 1; /* add the row to lpsolve */ if(!add_constraintex(lp, j, row, colno, LE, 75)) ret = 3; } if(ret == 0) { set_add_rowmode(lp, FALSE); /* rowmode should be turned off again when done building the model */ /* set the objective function (143 x + 60 y) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 143; colno[j] = 2; /* second column */ row[j++] = 60; /* set the objective in lpsolve */ if(!set_obj_fnex(lp, j, row, colno)) ret = 4; } if(ret == 0) { /* set the object direction to maximize */ set_maxim(lp); /* just out of curioucity, now show the model in lp format on screen */ /* this only works if this is a console application. If not, use write_lp and a filename */ write_LP(lp, stdout); /* write_lp(lp, "model.lp"); */ /* I only want to see important messages on screen while solving */ set_verbose(lp, IMPORTANT); /* Now let lpsolve calculate a solution */ ret = solve(lp); if(ret == OPTIMAL) ret = 0; else ret = 5; } if(ret == 0) { /* a solution is calculated, now lets get some results */ /* objective value */ printf("Objective value: %f\n", get_objective(lp)); /* variable values */ get_variables(lp, row); for(j = 0; j < Ncol; j++) printf("%s: %f\n", get_col_name(lp, j + 1), row[j]); /* we are done now */ } /* free allocated memory */ if(row != NULL) free(row); if(colno != NULL) free(colno); if(lp != NULL) { /* clean up such that all used memory by lpsolve is freed */ delete_lp(lp); } return(ret); } int main() { demo(); }
When this is run, the following is shown on screen:
/* Objective function */ max: +143 x +60 y; /* Constraints */ +120 x +210 y <= 15000; +110 x +30 y <= 4000; +x +y <= 75; Objective value: 6315.625000 x: 21.875000 y: 53.125000
Note that this example is very limited. It is also possible to set bounds on variables, ranges on constraints, define variables as integer, get more result information, changing solver options and parameters and much more. See lp_solve API reference for an overview of the API to do this.
The example model can be formulated as follows in Java:
/* demo.java */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import lpsolve.*; public class Demo { public Demo() { } public int execute() throws LpSolveException { LpSolve lp; int Ncol, j, ret = 0; /* We will build the model row by row So we start with creating a model with 0 rows and 2 columns */ Ncol = 2; /* there are two variables in the model */ /* create space large enough for one row */ int[] colno = new int[Ncol]; double[] row = new double[Ncol]; lp = LpSolve.makeLp(0, Ncol); if(lp.getLp() == 0) ret = 1; /* couldn't construct a new model... */ if(ret == 0) { /* let us name our variables. Not required, but can be useful for debugging */ lp.setColName(1, "x"); lp.setColName(2, "y"); lp.setAddRowmode(true); /* makes building the model faster if it is done rows by row */ /* construct first row (120 x + 210 y <= 15000) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 120; colno[j] = 2; /* second column */ row[j++] = 210; /* add the row to lpsolve */ lp.addConstraintex(j, row, colno, LpSolve.LE, 15000); } if(ret == 0) { /* construct second row (110 x + 30 y <= 4000) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 110; colno[j] = 2; /* second column */ row[j++] = 30; /* add the row to lpsolve */ lp.addConstraintex(j, row, colno, LpSolve.LE, 4000); } if(ret == 0) { /* construct third row (x + y <= 75) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 1; colno[j] = 2; /* second column */ row[j++] = 1; /* add the row to lpsolve */ lp.addConstraintex(j, row, colno, LpSolve.LE, 75); } if(ret == 0) { lp.setAddRowmode(false); /* rowmode should be turned off again when done building the model */ /* set the objective function (143 x + 60 y) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 143; colno[j] = 2; /* second column */ row[j++] = 60; /* set the objective in lpsolve */ lp.setObjFnex(j, row, colno); } if(ret == 0) { /* set the object direction to maximize */ lp.setMaxim(); /* just out of curioucity, now generate the model in lp format in file model.lp */ lp.writeLp("model.lp"); /* I only want to see important messages on screen while solving */ lp.setVerbose(LpSolve.IMPORTANT); /* Now let lpsolve calculate a solution */ ret = lp.solve(); if(ret == LpSolve.OPTIMAL) ret = 0; else ret = 5; } if(ret == 0) { /* a solution is calculated, now lets get some results */ /* objective value */ System.out.println("Objective value: " + lp.getObjective()); /* variable values */ lp.getVariables(row); for(j = 0; j < Ncol; j++) System.out.println(lp.getColName(j + 1) + ": " + row[j]); /* we are done now */ } /* clean up such that all used memory by lpsolve is freed */ if(lp.getLp() != 0) lp.deleteLp(); return(ret); } public static void main(String[] args) { try { new Demo().execute(); } catch (LpSolveException e) { e.printStackTrace(); } } }
When this is run, the following is shown on screen:
Objective value: 6315.625 x: 21.875000000000007 y: 53.12499999999999
And a file model.lp is created with the following contents:
/* Objective function */ max: +143 x +60 y; /* Constraints */ +120 x +210 y <= 15000; +110 x +30 y <= 4000; +x +y <= 75;
Note that this example is very limited. It is also possible to set bounds on variables, ranges on constraints, define variables as integer, get more result information, changing solver options and parameters and much more. See lp_solve API reference for an overview of the API to do this.
Also note that the API names in Java are a bit different than in the native lpsolve API and the lp argument is not there. See the lpsolve Java wrapper documentation for more details.
The example model can be formulated as follows in Delphi or Free Pascal:
program demo; {$APPTYPE CONSOLE} uses SysUtils, lpsolve; var Ncol, j, ret: integer; colno: PIntArray; row: PFloatArray; lp: THandle; begin ret := 0; colno := nil; row := nil; (* We will build the model row by row So we start with creating a model with 0 rows and 2 columns *) Ncol := 2; (* there are two variables in the model *) lp := make_lp(0, Ncol); if (lp = 0) then ret := 1; (* couldn't construct a new model... *) (* let us name our variables. Not required, but can be usefull for debugging *) set_col_name(lp, 1, 'x'); set_col_name(lp, 2, 'y'); if (ret = 0) then begin (* create space large enough for one row *) GetMem(colno, SizeOf(integer) * Ncol); GetMem(row, SizeOf(double) * Ncol); if ((colno = nil) or (row = nil)) then ret := 2; end; if (ret = 0) then begin set_add_rowmode(lp, true); (* makes building the model faster if it is done rows by row *) (* construct first row (120 x + 210 y <= 15000) *) j := 0; colno^[j] := 1; (* first column *) row^[j] := 120; j := j + 1; colno^[j] := 2; (* second column *) row^[j] := 210; j := j + 1; (* add the row to lp_solve *) if (not add_constraintex(lp, j, row, colno, LE, 15000)) then ret := 3; end; if (ret = 0) then begin (* construct second row (110 x + 30 y <= 4000) *) j := 0; colno^[j] := 1; (* first column *) row^[j] := 110; j := j + 1; colno^[j] := 2; (* second column *) row^[j] := 30; j := j + 1; (* add the row to lp_solve *) if (not add_constraintex(lp, j, row, colno, LE, 4000)) then ret := 3; end; if (ret = 0) then begin (* construct third row (x + y <= 75) *) j := 0; colno^[j] := 1; (* first column *) row^[j] := 1; j := j + 1; colno^[j] := 2; (* second column *) row^[j] := 1; j := j + 1; (* add the row to lp_solve *) if (not add_constraintex(lp, j, row, colno, LE, 75)) then ret := 3; end; if (ret = 0) then begin set_add_rowmode(lp, false); (* rowmode should be turned off again when done building the model *) (* set the objective function (143 x + 60 y) *) j := 0; colno^[j] := 1; (* first column *) row^[j] := 143; j := j + 1; colno^[j] := 2; (* second column *) row^[j] := 60; j := j + 1; (* set the objective in lp_solve *) if (not set_obj_fnex(lp, j, row, colno)) then ret := 4; end; if (ret = 0) then begin (* set the object direction to maximize *) set_maxim(lp); (* just out of curioucity, now show the model in lp format *) write_lp(lp, 'model.lp'); (* I only want to see importand messages on screen while solving *) set_verbose(lp, IMPORTANT); (* Now let lp_solve calculate a solution *) ret := solve(lp); if (ret = OPTIMAL) then ret := 0 else ret := 5; end; if (ret = 0) then begin (* a solution is calculated, now lets get some results *) (* objective value *) writeln(format('Objective value: %f', [get_objective(lp)])); (* variable values *) get_variables(lp, row); for j := 0 to Ncol-1 do writeln(format('%s: %f', [get_col_name(lp, j + 1), row^[j]])); (* we are done now *) end; (* free allocated memory *) if (row <> nil) then FreeMem(row); if (colno <> nil) then FreeMem(colno); if(lp <> 0) then begin (* clean up such that all used memory by lp_solve is freeed *) delete_lp(lp); end; end.
When this is run, the following is shown:
Objective value: 6315.63 x: 21.88 y: 53.12
And a file model.lp is created with the following contents:
/* Objective function */ max: +143 x +60 y; /* Constraints */ +120 x +210 y <= 15000; +110 x +30 y <= 4000; +x +y <= 75;
Note that a unit lpsolve.pas+lpsolve.inc is needed for this to work. This is available via the Delphi example.
Note that this example is very limited. It is also possible to set bounds on variables, ranges on constraints, define variables as integer, get more result information, changing solver options and parameters and much more. See lp_solve API reference for an overview of the API to do this.
The example model can be formulated as follows in VB or VBScript:
Option Explicit 'demo Private lpsolve As lpsolve55 Sub Main() Set lpsolve = New lpsolve55 lpsolve.Init "." Demo Set lpsolve = Nothing End Sub Private Function Demo() As Integer Dim lp As Long Dim Ncol As Long, colno() As Long Dim j As Integer, ret As Integer Dim row() As Double With lpsolve ' We will build the model row by row ' So we start with creating a model with 0 rows and 2 columns Ncol = 2 ' there are two variables in the model lp = .make_lp(0, Ncol) If lp = 0 Then ret = 1 ' couldn't construct a new model... End If If ret = 0 Then ' let us name our variables. Not required, but can be useful for debugging .set_col_name lp, 1, "x" .set_col_name lp, 2, "y" ' create space large enough for one row ReDim colno(0 To Ncol - 1) ReDim row(0 To Ncol - 1) End If If ret = 0 Then .set_add_rowmode lp, True ' makes building the model faster if it is done rows by row ' construct first row (120 x + 210 y <= 15000) j = 0 colno(j) = 1 ' first column row(j) = 120 j = j + 1 colno(j) = 2 ' second column row(j) = 210 j = j + 1 ' add the row to lpsolve If .add_constraintex(lp, j, row(0), colno(0), LE, 15000) = False Then ret = 3 End If End If If ret = 0 Then ' construct second row (110 x + 30 y <= 4000) j = 0 colno(j) = 1 ' first column row(j) = 110 j = j + 1 colno(j) = 2 ' second column row(j) = 30 j = j + 1 ' add the row to lpsolve If .add_constraintex(lp, j, row(0), colno(0), LE, 4000) = False Then ret = 3 End If End If If ret = 0 Then ' construct third row (x + y <= 75) j = 0 colno(j) = 1 ' first column row(j) = 1 j = j + 1 colno(j) = 2 ' second column row(j) = 1 j = j + 1 ' add the row to lpsolve If .add_constraintex(lp, j, row(0), colno(0), LE, 75) = False Then ret = 3 End If End If If ret = 0 Then .set_add_rowmode lp, False ' rowmode should be turned off again when done building the model ' set the objective function (143 x + 60 y) j = 0 colno(j) = 1 ' first column row(j) = 143 j = j + 1 colno(j) = 2 ' second column row(j) = 60 j = j + 1 ' set the objective in lpsolve If .set_obj_fnex(lp, j, row(0), colno(0)) = False Then ret = 4 End If End If If ret = 0 Then ' set the object direction to maximize .set_maxim lp ' just out of curioucity, now show the model in lp format on screen ' this only works if this is a console application. If not, use write_lp and a filename .write_lp lp, "model.lp" ' I only want to see important messages on screen while solving .set_verbose lp, 3 ' Now let lpsolve calculate a solution ret = .solve(lp) If ret = OPTIMAL Then ret = 0 Else ret = 5 End If End If If ret = 0 Then ' a solution is calculated, now lets get some results ' objective value Debug.Print "Objective value: " & .get_objective(lp) ' variable values .get_variables lp, row(0) For j = 1 To Ncol Debug.Print .get_col_name(lp, j) & ": " & row(j - 1) Next ' we are done now End If ' free allocated memory Erase row Erase colno If lp <> 0 Then ' clean up such that all used memory by lpsolve is freed .delete_lp lp End If Demo = ret End With End Function
When this is run, the following is shown in the debug window:
Objective value: 6315.625 x: 21.875 y: 53.125
And a file model.lp is created with the following contents:
/* Objective function */ max: +143 x +60 y; /* Constraints */ +120 x +210 y <= 15000; +110 x +30 y <= 4000; +x +y <= 75;
Note that a class lpsolve55.cls or the lpsolve55 COM object is needed for this to work. The class is available via the VB example and the COM object is also available.
Note that this example is very limited. It is also possible to set bounds on variables, ranges on constraints, define variables as integer, get more result information, changing solver options and parameters and much more. See lp_solve API reference for an overview of the API to do this.
The example model can be formulated as follows in VB.NET:
Option Strict Off Option Explicit On Module Module1 'demo Private lpsolve As lpsolve55 Public Sub Main() lpsolve = New lpsolve55 lpsolve.Init(".") Demo() lpsolve = Nothing End Sub Private Function Demo() As Integer Dim lp As Integer Dim Ncol As Integer Dim colno() As Integer Dim j, ret As Short Dim row() As Double With lpsolve ' We will build the model row by row ' So we start with creating a model with 0 rows and 2 columns Ncol = 2 ' there are two variables in the model lp = .make_lp(0, Ncol) If lp = 0 Then ret = 1 ' couldn't construct a new model... End If If ret = 0 Then ' let us name our variables. Not required, but can be useful for debugging .set_col_name(lp, 1, "x") .set_col_name(lp, 2, "y") ' create space large enough for one row ReDim colno(Ncol - 1) ReDim row(Ncol - 1) End If If ret = 0 Then .set_add_rowmode(lp, True) ' makes building the model faster if it is done rows by row ' construct first row (120 x + 210 y <= 15000) j = 0 colno(j) = 1 ' first column row(j) = 120 j = j + 1 colno(j) = 2 ' second column row(j) = 210 j = j + 1 ' add the row to lpsolve If .add_constraintex(lp, j, row(0), colno(0), lpsolve55.lpsolve_constr_types.LE, 15000) = False Then ret = 3 End If End If If ret = 0 Then ' construct second row (110 x + 30 y <= 4000) j = 0 colno(j) = 1 ' first column row(j) = 110 j = j + 1 colno(j) = 2 ' second column row(j) = 30 j = j + 1 ' add the row to lpsolve If .add_constraintex(lp, j, row(0), colno(0), lpsolve55.lpsolve_constr_types.LE, 4000) = False Then ret = 3 End If End If If ret = 0 Then ' construct third row (x + y <= 75) j = 0 colno(j) = 1 ' first column row(j) = 1 j = j + 1 colno(j) = 2 ' second column row(j) = 1 j = j + 1 ' add the row to lpsolve If .add_constraintex(lp, j, row(0), colno(0), lpsolve55.lpsolve_constr_types.LE, 75) = False Then ret = 3 End If End If If ret = 0 Then .set_add_rowmode(lp, False) ' rowmode should be turned off again when done building the model ' set the objective function (143 x + 60 y) j = 0 colno(j) = 1 ' first column row(j) = 143 j = j + 1 colno(j) = 2 ' second column row(j) = 60 j = j + 1 ' set the objective in lpsolve If .set_obj_fnex(lp, j, row(0), colno(0)) = False Then ret = 4 End If End If If ret = 0 Then ' set the object direction to maximize .set_maxim(lp) ' just out of curioucity, now show the model in lp format on screen ' this only works if this is a console application. If not, use write_lp and a filename .write_lp(lp, "model.lp") ' I only want to see important messages on screen while solving .set_verbose(lp, 3) ' Now let lpsolve calculate a solution ret = .solve(lp) If ret = lpsolve55.lpsolve_return.OPTIMAL Then ret = 0 Else ret = 5 End If End If If ret = 0 Then ' a solution is calculated, now lets get some results ' objective value System.Diagnostics.Debug.WriteLine("Objective value: " & .get_objective(lp)) ' variable values .get_variables(lp, row(0)) For j = 1 To Ncol System.Diagnostics.Debug.WriteLine(.get_col_name(lp, j) & ": " & row(j - 1)) Next ' we are done now End If ' free allocated memory Erase row Erase colno If lp <> 0 Then ' clean up such that all used memory by lpsolve is freed .delete_lp(lp) End If Demo = ret End With End Function End Module
When this is run, the following is shown in the debug window:
Objective value: 6315.625 x: 21.875 y: 53.125
And a file model.lp is created with the following contents:
/* Objective function */ max: +143 x +60 y; /* Constraints */ +120 x +210 y <= 15000; +110 x +30 y <= 4000; +x +y <= 75;
Note that a class lpsolve55.vb is needed for this to work. The class is available via the VB.NET example.
Note that this example is very limited. It is also possible to set bounds on variables, ranges on constraints, define variables as integer, get more result information, changing solver options and parameters and much more. See lp_solve API reference for an overview of the API to do this.
The example model can be formulated as follows in C#.NET:
using System.Windows.Forms; using lpsolve55; /* demo.cs */ namespace demo { public class demo { public static void Main() { lpsolve.Init("."); Demo(); } private static int Demo() { int lp; int Ncol; int[] colno; int j, ret = 0; double[] row; /* We will build the model row by row */ /* So we start with creating a model with 0 rows and 2 columns */ Ncol = 2; /* there are two variables in the model */ lp = lpsolve.make_lp(0, Ncol); if (lp == 0) ret = 1; /* couldn't construct a new model... */ if (ret == 0) { /* let us name our variables. Not required, but can be useful for debugging */ lpsolve.set_col_name(lp, 1, "x"); lpsolve.set_col_name(lp, 2, "y"); } /* create space large enough for one row */ colno = new int[Ncol]; row = new double[Ncol]; if (ret == 0) { lpsolve.set_add_rowmode(lp, true); /* makes building the model faster if it is done rows by row */ /* construct first row (120 x + 210 y <= 15000) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 120; colno[j] = 2; /* second column */ row[j++] = 210; /* add the row to lpsolve */ if (lpsolve.add_constraintex(lp, j, ref row[0], ref colno[0], lpsolve.lpsolve_constr_types.LE, 15000) == false) ret = 3; } if (ret == 0) { /* construct second row (110 x + 30 y <= 4000) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 110; colno[j] = 2; /* second column */ row[j++] = 30; /* add the row to lpsolve */ if (lpsolve.add_constraintex(lp, j, ref row[0], ref colno[0], lpsolve.lpsolve_constr_types.LE, 4000) == false) ret = 3; } if (ret == 0) { /* construct third row (x + y <= 75) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 1; colno[j] = 2; /* second column */ row[j++] = 1; /* add the row to lpsolve */ if (lpsolve.add_constraintex(lp, j, ref row[0], ref colno[0], lpsolve.lpsolve_constr_types.LE, 75) == false) ret = 3; } if (ret == 0) { lpsolve.set_add_rowmode(lp, false); /* rowmode should be turned off again when done building the model */ /* set the objective function (143 x + 60 y) */ j = 0; colno[j] = 1; /* first column */ row[j++] = 143; colno[j] = 2; /* second column */ row[j++] = 60; /* set the objective in lpsolve */ if (lpsolve.set_obj_fnex(lp, j, ref row[0], ref colno[0]) == false) ret = 4; } if (ret == 0) { lpsolve.lpsolve_return s; /* set the object direction to maximize */ lpsolve.set_maxim(lp); /* just out of curioucity, now show the model in lp format on screen */ /* this only works if this is a console application. If not, use write_lp and a filename */ lpsolve.write_lp(lp, "model.lp"); /* I only want to see important messages on screen while solving */ lpsolve.set_verbose(lp, 3); /* Now let lpsolve calculate a solution */ s = lpsolve.solve(lp); if (s == lpsolve.lpsolve_return.OPTIMAL) ret = 0; else ret = 5; } if (ret == 0) { /* a solution is calculated, now lets get some results */ /* objective value */ System.Diagnostics.Debug.WriteLine("Objective value: " + lpsolve.get_objective(lp)); /* variable values */ lpsolve.get_variables(lp, ref row[0]); for(j = 0; j < Ncol; j++) System.Diagnostics.Debug.WriteLine(lpsolve.get_col_name(lp, j + 1) + ": " + row[j]); /* we are done now */ } /* free allocated memory */ if (lp != 0) { /* clean up such that all used memory by lpsolve is freed */ lpsolve.delete_lp(lp); } return(ret); } //Demo } }
When this is run, the following is shown in the debug window:
Objective value: 6315.625 x: 21.875 y: 53.125
And a file model.lp is created with the following contents:
/* Objective function */ max: +143 x +60 y; /* Constraints */ +120 x +210 y <= 15000; +110 x +30 y <= 4000; +x +y <= 75;
Note that a class lpsolve55.cs is needed for this to work. The class is available via the CS.NET example.
Note that this example is very limited. It is also possible to set bounds on variables, ranges on constraints, define variables as integer, get more result information, changing solver options and parameters and much more. See lp_solve API reference for an overview of the API to do this.
doc/is_lag_trace.htm 0000644 0001750 0001750 00000004365 10237176660 013435 0 ustar rene rene
is_lag_traceReturns a flag if Lagrangian progression must be printed while solving. unsigned char is_lag_trace(lprec *lp); Return Value is_lag_trace returns TRUE or FALSE. Print or do not print. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI Remarks The is_lag_trace function returns a flag if Lagrangian progression must be printed while solving. This function is mend for debugging purposes. The default is not to print (FALSE). Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_lag_trace |
lp_solve Frequently Asked Questions
- Where can I find the latest version of lp_solve?
- Can I use lp_solve in commercial code?
- Please explain what this LGPL license exactly means. I don't understand it. lp_solve used as compiled library? Yes No ----------- lp_solve Yes | B1 | B2 | code was |-----|-----| modified? No | A | B3 | -----------
A: "Work that uses the library" - But how much does lp_solve costs me? lp_solve is totally free - gratis - if you follow the rules of the LGPL. You may of course ask money for code you have developed or added, but only for that part, and the openness provisions of the LGPL have to be respected. If you are not willing to respect this, then the only recourse is that you seek an agreement with the copyright holders of the appropriate parts of lp_solve. - How should lp_solve be cited when I use it? lpsolve citation data ---------------------- Description : Open source (Mixed-Integer) Linear Programming system Language : Multi-platform, pure ANSI C / POSIX source code, Lex/Yacc based parsing Official name : lp_solve (alternatively lpsolve) Release data : Version 5.1.0.0 dated 1 May 2004 Co-developers : Michel Berkelaar, Kjell Eikland, Peter Notebaert Licence terms : GNU LGPL (Lesser General Public Licence) Citation policy : General references as per LGPL Module specific references as specified thereinThis text is also in citations.txt
- What are the default bounds on variables?
- Is it possible to set negative bounds on variables?
- Is it possible to set a minus infinite lower bound on a variable?
- What is the layout of the lp/mps/CPLEX format?
- When I call the API call solve(), several messages are printed on screen. How can I
disable those messages?
- lp_solve fails to solve my model or it takes a very long time to solve my model.
What can I do?
- Can lp_solve handle non-linear equations?
- Can lp_solve handle ratios? Have you entered your model via Word? Then the problem will probably be that some characters have ascii codes that are not recognised by lp_solve. For example, Word changes the minus sign (-) to another character that also looks like a minus sign, but it is a bit longer. The ascii code of this character is different from the ascii code of the real minus sign and lp_solve has problem with it. However you see a - on screen. The solution is not to use Word to enter your lp-model. Notepad should be ok. Better is to use the LPSolve IDE.
- lp_solve prints the output on screen. Can I have the output also in a file?
- I have a constraint saying that x < 2, but lp_solve comes with a solution of 2, how comes?
- When I solve my model, I get a stack overflow error/core dump/protection error. What is wrong?
- Version 4 solves my models slower than version 3 did. What can I do?
- It takes a long time to build the model via the API interface. Especially
add_constraint, add_constraintex, str_add_constraint
seems to be slow. How can it be made faster?
- Can lp_solve give me the 'simplex tableau' of the model?
- Is there documentation about the API interface?
- What is the maximum number of rows/columns that lp_solve can handle?
- I use a programming language that is not listed as supported or for which there
are no examples. Can lp_solve be called from this language?
- The Windows examples don't work. I get an error running them. Some dll cannot be
found.
- Does lp_solve supports the mps free format?
- Does the lp_solve lp format support comments?
- I want to compile lp_solve myself, but I get link errors. Also what should I
do with lp.y, lex.l, lp_rlp.y, lp_rlp.l?
- I compile lp_solve myself, but I get link errors saying that main (or _main)
is already defined.
- I want to use the lpsolve dll, but when I compile my C/C++ program, I get link
errors. He doesn't find any of the lpsolve API routines. What am I doing wrong?
- lp.c and lex.c that are generated on my system are different from the
versions that can be found in the support folder in the files section. Are the
latest versions of these files on your site?
- When I start the lp_solve program, nothing
happens. I just get a blinking cursor. If I enter a command like lp1 = make_lp(0,4),
I get a parse error. What is wrong here? How do I use the program? ROWS N r_0 L C1 L r_2 COLUMNS MARK0000 'MARKER' 'INTORG' x1 r_0 1 C1 2 x1 r_2 -4 x2 r_0 -2 C1 1 x2 r_2 4 MARK0001 'MARKER' 'INTEND' RHS RHS C1 5 r_2 5 ENDATA
To enable this input format in the lp_solve program, use the -mps option.
- Is there no more user-friendly interface than the lp_solve command line program? |
has_XLIReturns if there is an external language interface (XLI) set. unsigned char has_XLI(lprec *lp); Return Value has_XLI returns TRUE if there is an XLI set, else FALSE. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI Remarks See External Language Interfaces for a complete description on XLIs. Example
See Also make_lp, copy_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, write_XLI, is_nativeXLI, set_XLI |
put_bb_branchfuncSpecifies a user function to select a B&B branching, given the column to branch on. void put_bb_branchfunc(lprec *lp, lphandleint_intfunc newbranch, void *bb_branchhandle); Return Value put_bb_branchfunc has no return value. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI newbranch The branch routine. bb_branchhandle A parameter that will be provided to the branch routine. Remarks Specifies a user function to select a B&B branching, given the column to branch on. With this function you can specify which branch must be taken first in the B&B algorithm. The floor or the ceiling. This overrules the setting of set_bb_floorfirst. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_bb_floorfirst, get_bb_floorfirst, set_var_branch, get_var_branch, set_var_weights, get_var_priority |
set_BFPSet basis factorization package. unsigned char set_BFP(lprec *lp, char *filename); Return Value set_BFP returns TRUE if the call has succeeded, else FALSE. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI filename The name of the BFP package. Currently following BFPs are implemented:
Remarks The set_BFP function sets the basis factorization package (BFP). See Basis Factorization Packages for a complete description on BFPs. Example
See Also make_lp, copy_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, has_BFP, is_nativeBFP |
Absolute valuesConstraintsLinear constraints are of the form: a1 x1 + a2 x2 + a3 x3 + ... <= maximum a1 x1 + a2 x2 + a3 x3 + ... >= minimum Where minimum and maximum are constants. lp_solve can only handle these kind of Linear equations. So what if absolute values must be formulated: abs(a1 x1 + a2 x2 + a3 x3) = 0 abs(a1 x1 + a2 x2 + a3 x3) <= maximum abs(a1 x1 + a2 x2 + a3 x3) >= minimum = 0 (or <= 0)This is the easiest case. If abs(X) must be equal to zero, then this can only be fulfilled if X is zero. So the condition can also be written as: a1 x1 + a2 x2 + a3 x3 = 0 <= maximumThis is a bit more complicated, but still quite easy. Let's first represent a1 x1 + a2 x2 + a3 x3 by X. So the condition becomes: abs(X) <= maximum What is in fact abs(X) ? It is X if X is positive or 0 and it is -X if X is negative. This also implies that maximum is always bigger than or equal to zero. Else the constraint would always be impossible (mathematical impossible with real numbers). The geometric representation of this is: ----+===============+---- -maximum 0 +maximum The section between -maximum and +maximum fulfils the constraint. So if X is positive, the restriction becomes: X <= maximum If X is negative, the restriction becomes: -X <= maximum And the fortunate thing is that if we need the one restriction that the other is always redundant. If X is positive, then -X is negative and thus always less than maximum (which is always positive, remember) and thus the second equation is then redundant. If X is negative, then it is always less than maximum (which is always positive, remember) and thus the first equation is then redundant. This can also be seen easily from the graphical representation. So just add the following two equations: X <= maximum -X <= maximum And the abs(X) <= maximum condition is fulfilled. And what if the condition is abs(X) + Y <= maximum With Y any linear combination. It is easy to see that the same reasoning can be used to become: X + Y <= maximum -X + Y <= maximum With the original definition of X this becomes: a1 x1 + a2 x2 + a3 x3 + Y <= maximum -a1 x1 - a2 x2 - a3 x3 + Y <= maximumSpecial case 1 abs(x1) + abs(x2) + ... <= maximum;First consider each abs(xi) value. From above, consider the following: xiabs >= xi; xiabs >= -xi;This makes xiabs >= abs(xi) Greater than or equal, but as is, not for sure equal. However, in combination with other constraints, this can become equal. If following constraint is added, and when active, then each xiabs will represent the absolute value of xi: x1abs + x2abs + ... <= maximum;So, for each abs(xi) variable in the constraint, add a new variable xiabs and add two extra constraints for it. Then replace abs(xi) by xiabs in the constraint and the condition is fulfilled. Note that the objective may be minimization or maximization, it doesn't matter. Note that the variables may have an extra coefficient, but not negative! If the sign would be negative, then xiabs will not have the intention to become as small as possible, but as large as possible and the result would be that xiabs would not be equal to abs(xi). It could become larger. Example: max: x1 + 2x2 - 4x3 -3x4; x1 + x2 <= 5; 2x1 - x2 >= 0; -x1 + 3x2 >= 0; x3 + x4 >= .5; x3 >= 1.1; x3 <= 10; abs(x2) + abs(x4) <= 1.5; /* Note that this is not a valid expression. It will be converted. */ free x2, x4;The converted model becomes: max: x1 + 2x2 - 4x3 -3x4; x1 + x2 <= 5; 2x1 - x2 >= 0; -x1 + 3x2 >= 0; x3 + x4 >= .5; x3 >= 1.1; x3 <= 10; x2abs >= x2; x2abs >= -x2; x4abs >= x4; x4abs >= -x4; x2abs + x4abs <= 1.5; free x2, x4;The result is: Value of objective function: 2.6 Actual values of the variables: x1 3.75 x2 1.25 x3 1.1 x4 -0.25 x2abs 1.25 x4abs 0.25 >= minimumLet's first represent a1 x1 + a2 x2 + a3 x3 by X. So the condition becomes: abs(X) >= minimum What is in fact abs(X) ? It is X if X is positive or 0 and it is -X if X is negative. This also implies that minimum should always be bigger than zero. Else the constraint would always be fulfilled and there is no point in having the constraint. The geometric representation of this is: ====+---------------+==== -minimum 0 +minimum The section not between -minimum and +minimum fulfils the constraint. So if X is positive, the restriction becomes: X >= minimum If X is negative, the restriction becomes: -X >= minimum Unfortunately, the trick as for a maximum cannot be used here. If X is positive, then -X is not greater than minimum, in contrary ... It can also be seen from the graphical representation that this restriction is discontinue. This has as effect that it is not possible to convert this into a set of linear equations. A possible approach to overcome this is making use of integer variables. In particular by using a binary variable B: X + M * B >= minimum -X + M * (1 - B) >= minimum M is a large enough constant. See later. If B is 0, then the equations can be written as: X >= minimum -X + M >= minimum So in this case, the restriction X >= minimum is active. X must be positive and larger than minimum. With M large enough, the second constraint is always fulfilled. If B is 1, then the equations can be written as: X + M >= minimum -X >= minimum So in this case, the restriction -X >= minimum is active. X must be negative and -X be larger than minimum. With M large enough, the first constraint is always fulfilled. It is important to use a realistic value for M. Don't use for example 1e30 for it. This creates numerical instabilities and even if not then tolerances will give problem. Because of tolerances, B may not be zero, but actually for example 1e-20. This multiplied with 1e30 gives not zero, but 1e10! This results in X + 1e10 >= minimum instead of X >= minimum. Not what was mathematically formulated! So how big must M be? If we can predict how large X can become (absolutely), then we can predict a maximum value needed for M for this to work. If abs(X) cannot be larger than maximum, then M can be minimum+maximum. In most cases, it is possible to determine a reasonable upper bound for X. In lp-format, the needed equations are: X + M * B >= minimum; X + M * B <= M - minimum; B <= 1; int B; And what if the condition is abs(X) + Y >= minimum With Y any linear combination. It is easy to see that the same reasoning can be used to become: X + M * B + Y >= minimum -X + M * (1 - B) + Y >= minimum With M >= minimum - Y + abs(X) In lp-format: X + M * B + Y >= minimum; X + M * B - Y <= M - minimum B <= 1; int B; Objective functionThe objective function is of the form: min or max: a1 x1 + a2 x2 + a3 x3 + ... What if there is an absolute value in the objective: abs(a1 x1 + a2 x2 + a3 x3) + a4 x4 + a5 x5 Let's first represent a1 x1 + a2 x2 + a3 x3 by X and a4 x4 + a5 x5 by Y. Then the objective becomes: abs(X) + Y Depending on the sign before the abs and the objective direction, there is an easy and a harder way to solve this. minimization and sign is positive or maximization and sign is negative.min: abs(X) + Y or max: -abs(X) + Y In these two situations, abs(X) will be as small as possible, ideally zero. We can use that fact. Add one variable X' and two constraints to the model: X <= X' -X <= X' And replace in the objective abs(X) with X': min: X' + Y or max: -X' + Y That is all. So how does this work? There are 3 cases to consider: X > 0In this case, -X is negative and the second constraint -X <= X' is always fulfilled because X' is implicitly >= 0. The first constraint X <= X' is however different. Because X is positive, X' must be at least as large as X. But because X' is in the objective in such a way that is tends to be as small as possible, X' will be equal to X. So X' is abs(X) in this case. X < 0In this case, X is negative and the first constraint X <= X' is always fulfilled because X' is implicitly >= 0. The second constraint -X <= X' is however different. Because X is negative (-X positive), X' must be at least as large as -X. But because X' is in the objective in such a way that is tends to be as small as possible, X' will be equal to -X. So X' is abs(X) in this case. X = 0In this case, both constraints are always fulfilled because X' is implicitly >= 0. Because X' is in the objective in such a way that is tends to be as small as possible, X' will be equal to X, in this case 0. So X' is abs(X). So in all cases, X' equals abs(X) With the original definition of X and Y this becomes: min: X' + a4 x4 + a5 x5 or max: -X' + a4 x4 + a5 x5 a1 x1 + a2 x2 + a3 x3 <= X' -a1 x1 - a2 x2 - a3 x3 <= X' minimization and sign is negative or maximization and sign is positive.min: -abs(X) + Y or max: abs(X) + Y This is a different story. abs(X) now tends to be as large as possible. So the previous trick cannot be used now. A possible approach to overcome this is making use of integer variables. In particular by using a binary variable B and adding a variable X'. Add following constraints to the model: X + M * B >= X' -X + M * (1 - B) >= X' X <= X' -X <= X' And replace in the objective abs(X) with X': min: -X' + Y or max: X' + Y That is all. So how does this work? In fact this is a combination of a maximum and minimum constraint on an absolute expression. X' represents the absolute expression and is used in the objective. M is a large enough constant. See later. If B is 0, then the equations can be written as: X >= X' -X + M >= X' X <= X' -X <= X' So in this case, the restriction X >= X' is active. X must be positive and larger than X'. With M large enough, the second constraint is always fulfilled. The third constraint says that X <= X'. The forth constraint is always fulfilled. In fact the first and third constraint have as result that X' equals X, which is positive in this case. If B is 1, then the equations can be written as: X + M >= X' -X >= X' X <= X' -X <= X' So in this case, the restriction -X >= X' is active. X must be negative and -X be larger than X'. With M large enough, the first constraint is always fulfilled. The third constraint is always fulfilled. The forth constraint says that -X < X'. In fact the second and forth constraint have as result that X' equals -X, which is positive in this case. It is important to use a realistic value for M. Don't use for example 1e30 for it. This creates numerical instabilities and even if not then tolerances will give problem. Because of tolerances, B may not be zero, but actually for example 1e-20. This multiplied with 1e30 gives not zero, but 1e10! This results in X + 1e10 >= X' instead of X >= X'. Not what was mathematically formulated! So how big must M be? If we can predict how large X can become (absolutely), then we can predict a maximum value needed for M for this to work. If abs(X) cannot be larger than maximum, then M can be 2 * maximum. In most cases, it is possible to determine a reasonable upper bound for X. In lp-format, the needed equations are: max: X' + Y; X + M * B - X' >= 0; X + M * B + X' <= M; X <= X' -X <= X' B <= 1; int B; |
set_rh_vec, str_set_rh_vecSet the right hand side (RHS) vector (column 0). void set_rh_vec(lprec *lp, REAL *rh); unsigned char str_set_rh_vec(lprec *lp, char *rh_string); Return Value set_rh_vec has no return value. str_set_rh_vec returns TRUE (1) if the operation was successful. A return value of FALSE (0) indicates an error. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI rh An array with row elements that contains the values of the RHS. rh_string A string with row elements that contains the values of the RHS. Each element must be separated by space(s). Remarks
The set_rh_vec, str_set_rh_vec functions set all values of the
RHS vector (column 0) at once. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_rh, get_rh, add_constraint, add_constraintex, str_add_constraint, add_column, add_columnex, str_add_column, get_mat, get_column, get_columnex, set_column, set_columnex, get_row, get_rowex, set_row, set_rowex |
is_debugReturns a flag if all intermediate results and the branch-and-bound decisions must be printed while solving. unsigned char is_debug(lprec *lp); Return Value is_debug returns TRUE or FALSE. Debug or do not debug. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI Remarks The is_debug function returns a flag if all intermediate results and the branch-and-bound decisions must be printed while solving. This function is mend for debugging purposes. The default is not to debug (FALSE). Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_debug |
get_scalelimitSets the relative scaling convergence criterion for the active scaling mode. REAL get_scalelimit(lprec *lp); Return Value get_scalelimit returns the relative scaling convergence criterion for the active scaling mode; the integer part specifies the maximum number of iterations. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI scalelimit maximum number of iterations Remarks The get_scalelimit function the relative scaling convergence criterion for the active scaling mode; the integer part specifies the maximum number of iterations (default is 5). Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_scalelimit, set_scaling, get_scaling, is_integerscaling |
set_basisvarThis is an internal function that has been published for special purposes. It should generally not be used. int set_basisvar(lprec *lp, int basisPos, int enteringCol); Return Value Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI basisPos enteringCol Remarks Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
lpsolve.* |
lpsolve.LpSolve | ||
public static final int |
ANTIDEGEN_BOUNDFLIP |
512 |
public static final int |
ANTIDEGEN_COLUMNCHECK |
2 |
public static final int |
ANTIDEGEN_DURINGBB |
128 |
public static final int |
ANTIDEGEN_DYNAMIC |
64 |
public static final int |
ANTIDEGEN_FIXEDVARS |
1 |
public static final int |
ANTIDEGEN_INFEASIBLE |
32 |
public static final int |
ANTIDEGEN_LOSTFEAS |
16 |
public static final int |
ANTIDEGEN_NONE |
0 |
public static final int |
ANTIDEGEN_NUMFAILURE |
8 |
public static final int |
ANTIDEGEN_RHSPERTURB |
256 |
public static final int |
ANTIDEGEN_STALLING |
4 |
public static final int |
AUTOMATIC |
2 |
public static final int |
BRANCH_AUTOMATIC |
2 |
public static final int |
BRANCH_DEFAULT |
3 |
public static final int |
BRANCH_CEILING |
0 |
public static final int |
BRANCH_FLOOR |
1 |
public static final int |
CRASH_MOSTFEASIBLE |
2 |
public static final int |
CRASH_NOTHING |
0 |
public static final int |
CRITICAL |
1 |
public static final int |
DATAIGNORED |
-4 |
public static final int |
DEGENERATE |
4 |
public static final int |
DETAILED |
5 |
public static final int |
DYNAMIC |
4 |
public static final int |
EQ |
3 |
public static final int |
FALSE |
0 |
public static final int |
FEASFOUND |
12 |
public static final int |
FR |
0 |
public static final int |
FULL |
6 |
public static final int |
PRESOLVED |
9 |
public static final int |
GE |
2 |
public static final int |
IMPORTANT |
3 |
public static final int |
IMPROVE_BBSIMPLEX |
8 |
public static final int |
IMPROVE_DUALFEAS |
2 |
public static final int |
IMPROVE_NONE |
0 |
public static final int |
IMPROVE_SOLUTION |
1 |
public static final int |
IMPROVE_THETAGAP |
4 |
public static final int |
INFEASIBLE |
2 |
public static final int |
LE |
1 |
public static final int |
MSG_INITPSEUDOCOST |
8192 |
public static final int |
MSG_INVERT |
4 |
public static final int |
MSG_ITERATION |
2 |
public static final int |
MSG_LPBETTER |
64 |
public static final int |
MSG_LPEQUAL |
32 |
public static final int |
MSG_LPFEASIBLE |
8 |
public static final int |
MSG_LPOPTIMAL |
16 |
public static final int |
MSG_MILPBETTER |
512 |
public static final int |
MSG_MILPEQUAL |
256 |
public static final int |
MSG_MILPFEASIBLE |
128 |
public static final int |
MSG_MILPOPTIMAL |
2048 |
public static final int |
MSG_MILPSTRATEGY |
1024 |
public static final int |
MSG_NONE |
0 |
public static final int |
MSG_PERFORMANCE |
4096 |
public static final int |
MSG_PRESOLVE |
1 |
public static final int |
NEUTRAL |
0 |
public static final int |
NOBFP |
-3 |
public static final int |
NODE_AUTOORDER |
8192 |
public static final int |
NODE_BRANCHREVERSEMODE |
16 |
public static final int |
NODE_BREADTHFIRSTMODE |
4096 |
public static final int |
NODE_DEPTHFIRSTMODE |
128 |
public static final int |
NODE_DYNAMICMODE |
1024 |
public static final int |
NODE_FIRSTSELECT |
0 |
public static final int |
NODE_FRACTIONSELECT |
3 |
public static final int |
NODE_GAPSELECT |
1 |
public static final int |
NODE_GREEDYMODE |
32 |
public static final int |
NODE_PSEUDOCOSTMODE |
64 |
public static final int |
NODE_PSEUDOCOSTSELECT |
4 |
public static final int |
NODE_PSEUDONONINTSELECT |
5 |
public static final int |
NODE_PSEUDORATIOSELECT |
6 |
public static final int |
NODE_RANDOMIZEMODE |
256 |
public static final int |
NODE_RANGESELECT |
2 |
public static final int |
NODE_RCOSTFIXING |
16384 |
public static final int |
NODE_RESTARTMODE |
2048 |
public static final int |
NODE_STRONGINIT |
32768 |
public static final int |
NODE_USERSELECT |
7 |
public static final int |
NODE_WEIGHTREVERSEMODE |
8 |
public static final int |
NOFEASFOUND |
13 |
public static final int |
NOMEMORY |
-2 |
public static final int |
NORMAL |
4 |
public static final int |
NOTRUN |
-1 |
public static final int |
NUMFAILURE |
5 |
public static final int |
OF |
4 |
public static final int |
OPTIMAL |
0 |
public static final int |
PRESOLVE_BOUNDS |
262144 |
public static final int |
PRESOLVE_COLDOMINATE |
16384 |
public static final int |
PRESOLVE_COLFIXDUAL |
131072 |
public static final int |
PRESOLVE_COLS |
2 |
public static final int |
PRESOLVE_DUALS |
524288 |
public static final int |
PRESOLVE_ELIMEQ2 |
256 |
public static final int |
PRESOLVE_IMPLIEDFREE |
512 |
public static final int |
PRESOLVE_IMPLIEDSLK |
65536 |
public static final int |
PRESOLVE_KNAPSACK |
128 |
public static final int |
PRESOLVE_LINDEP |
4 |
public static final int |
PRESOLVE_MERGEROWS |
32768 |
public static final int |
PRESOLVE_NONE |
0 |
public static final int |
PRESOLVE_PROBEFIX |
2048 |
public static final int |
PRESOLVE_PROBEREDUCE |
4096 |
public static final int |
PRESOLVE_REDUCEGCD |
1024 |
public static final int |
PRESOLVE_REDUCEMIP |
64 |
public static final int |
PRESOLVE_ROWDOMINATE |
8192 |
public static final int |
PRESOLVE_ROWS |
1 |
public static final int |
PRESOLVE_SENSDUALS |
1048576 |
public static final int |
PRESOLVE_SOS |
32 |
public static final int |
PRICE_ADAPTIVE |
32 |
public static final int |
PRICE_AUTOPARTIAL |
512 |
public static final int |
PRICE_HARRISTWOPASS |
4096 |
public static final int |
PRICE_HYBRID |
64 |
public static final int |
PRICE_LOOPALTERNATE |
2048 |
public static final int |
PRICE_LOOPLEFT |
1024 |
public static final int |
PRICE_METHODDEFAULT |
0 |
public static final int |
PRICE_MULTIPLE |
8 |
public static final int |
PRICE_PARTIAL |
16 |
public static final int |
PRICE_PRIMALFALLBACK |
4 |
public static final int |
PRICE_RANDOMIZE |
128 |
public static final int |
PRICE_TRUENORMINIT |
16384 |
public static final int |
PRICER_DANTZIG |
1 |
public static final int |
PRICER_DEVEX |
2 |
public static final int |
PRICER_FIRSTINDEX |
0 |
public static final int |
PRICER_STEEPESTEDGE |
3 |
public static final int |
PROCBREAK |
11 |
public static final int |
PROCFAIL |
10 |
public static final int |
RUNNING |
8 |
public static final int |
SCALE_COLSONLY |
1024 |
public static final int |
SCALE_CURTISREID |
7 |
public static final int |
SCALE_DYNUPDATE |
256 |
public static final int |
SCALE_EQUILIBRATE |
64 |
public static final int |
SCALE_EXTREME |
1 |
public static final int |
SCALE_GEOMETRIC |
4 |
public static final int |
SCALE_INTEGERS |
128 |
public static final int |
SCALE_LINEAR |
0 |
public static final int |
SCALE_LOGARITHMIC |
16 |
public static final int |
SCALE_MEAN |
3 |
public static final int |
SCALE_NONE |
0 |
public static final int |
SCALE_POWER2 |
32 |
public static final int |
SCALE_QUADRATIC |
8 |
public static final int |
SCALE_RANGE |
2 |
public static final int |
SCALE_ROWSONLY |
512 |
public static final int |
SCALE_USERWEIGHT |
31 |
public static final int |
SEVERE |
2 |
public static final int |
SIMPLEX_DEFAULT |
6 |
public static final int |
SIMPLEX_DUAL_DUAL |
10 |
public static final int |
SIMPLEX_DUAL_PRIMAL |
6 |
public static final int |
SIMPLEX_PRIMAL_DUAL |
9 |
public static final int |
SIMPLEX_PRIMAL_PRIMAL |
5 |
public static final int |
SUBOPTIMAL |
1 |
public static final int |
TIMEOUT |
7 |
public static final int |
TRUE |
1 |
public static final int |
UNBOUNDED |
3 |
public static final int |
UNKNOWNERROR |
-5 |
public static final int |
USERABORT |
6 |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
AbortListener
BbListener LogListener LpSolve LpSolveException MsgListener VersionInfo |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
Package lpsolve |
Class lpsolve.LpSolveException extends java.lang.Exception implements Serializable |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
AbortListener
BbListener LogListener LpSolve LpSolveException MsgListener VersionInfo |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
Each package has a page that contains a list of its classes and interfaces, with a summary for each. This page can contain four categories:
- Interfaces (italic)
- Classes
- Exceptions
- Errors
Each class, interface, nested class and nested interface has its own separate page. Each of these pages has three sections consisting of a class/interface description, summary tables, and detailed member descriptions:
Each summary entry contains the first sentence from the detailed description for that item. The summary entries are alphabetical, while the detailed descriptions are in the order they appear in the source code. This preserves the logical groupings established by the programmer.
- Class inheritance diagram
- Direct Subclasses
- All Known Subinterfaces
- All Known Implementing Classes
- Class/interface declaration
- Class/interface description
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary
- Field Detail
- Constructor Detail
- Method Detail
There is a Class Hierarchy page for all packages, plus a hierarchy for each package. Each hierarchy page contains a list of classes and a list of interfaces. The classes are organized by inheritance structure starting withjava.lang.Object
. The interfaces do not inherit fromjava.lang.Object
.
- When viewing the Overview page, clicking on "Tree" displays the hierarchy for all packages.
- When viewing a particular package, class or interface page, clicking "Tree" displays the hierarchy for only that package.
The Deprecated API page lists all of the API that have been deprecated. A deprecated API is not recommended for use, generally due to improvements, and a replacement API is usually given. Deprecated APIs may be removed in future implementations.
The Index contains an alphabetic list of all classes, interfaces, constructors, methods, and fields.
This help file applies to API documentation generated using the standard doclet.
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
Interfaces
AbortListener BbListener LogListener MsgListener |
Classes
LpSolve VersionInfo |
Exceptions
LpSolveException |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Classes that implement this interface may be passed
to the putLogfunc
method of the LpSolve
class.
LpSolve.putLogfunc(lpsolve.LogListener, java.lang.Object)
,
"lp_solve documentation for 'put_logfunc'"Method Summary | |
void |
logfunc(LpSolve problem,
java.lang.Object userhandle,
java.lang.String buf)
When set, the log routine is called when lp_solve has someting to report (error conditions or so). |
Method Detail |
public void logfunc(LpSolve problem, java.lang.Object userhandle, java.lang.String buf) throws LpSolveException
problem
- the problem this Listener was defined foruserhandle
- the userhandle object that was passed to putLogfunc
buf
- the log message
LpSolveException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Classes that implement this interface may be passed
to the putAbortfunc
method of the LpSolve
class.
LpSolve.putAbortfunc(lpsolve.AbortListener, java.lang.Object)
,
"lp_solve documentation for 'put_abortfunc'"Method Summary | |
boolean |
abortfunc(LpSolve problem,
java.lang.Object userhandle)
When set, the abort routine is called regularly during solve(). |
Method Detail |
public boolean abortfunc(LpSolve problem, java.lang.Object userhandle) throws LpSolveException
problem
- the problem this Listener was defined foruserhandle
- the userhandle object that was passed to putAbortfunc
LpSolveException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlpsolve.LpSolve
Object wrapper for a problem structure of the lp_solve library. Offers access to all lp_solve methods.
Method Summary | |
void |
addColumn(double[] column)
Add a column to the problem. |
void |
addColumnex(int count,
double[] column,
int[] rowno)
Add a column to the problem. |
void |
addConstraint(double[] row,
int constrType,
double rh)
Add a constraint to the problem. |
void |
addConstraintex(int count,
double[] row,
int[] colno,
int constrType,
double rh)
Add a constraint to the problem. |
void |
addLagCon(double[] row,
int constrType,
double rh)
Add a Lagrangian constraint to the problem. |
void |
addSOS(java.lang.String name,
int sostype,
int priority,
int count,
int[] sosvars,
double[] weights)
Add a SOS constraint. |
int |
columnInLp(double[] column)
Check if a column is already present in the problem. |
LpSolve |
copyLp()
Copy an existing lprec structure to a new lprec structure. |
void |
defaultBasis()
Sets the starting base to an all slack basis (the default simplex starting basis). |
void |
delColumn(int columnnr)
Remove a column from the problem. |
void |
delConstraint(int rownr)
Remove a constraint from the problem. |
void |
deleteLp()
Frees all resources allocated to this problem. |
void |
dualizeLp()
Create the dual of the current model. |
protected void |
finalize()
|
int |
getAntiDegen()
Returns the used degeneracy rule. |
void |
getBasis(int[] bascolumn,
boolean nonbasic)
Returns the basis of the lp. |
int |
getBasiscrash()
Returns which basis crash mode must be used. |
int |
getBbDepthlimit()
Returns the maximum branch-and-bound depth. |
int |
getBbFloorfirst()
Returns which branch to take first in branch-and-bound algorithm. |
int |
getBbRule()
Returns the branch-and-bound rule. |
boolean |
getBoundsTighter()
Returns if set bounds may only be tighter or also less restrictive. |
double |
getBreakAtValue()
Returns the value at which the branch-and-bound algorithm stops when the object value is better than this value. |
java.lang.String |
getColName(int colnr)
Gets the name of a column in the problem. |
void |
getColumn(int colnr,
double[] column)
Get all column elements from the matrix. |
int |
getColumnex(int colnr,
double[] column,
int[] nzrows)
Get the non-zero column elements from the matrix. |
void |
getConstraints(double[] var)
Returns the values of the constraints. |
short |
getConstrType(int rownr)
Get the type of a constraint. |
double |
getConstrValue(int rownr,
int count,
double[] primsolution,
int[] nzindex)
Gets the value of a constraint according to provided variable values. |
void |
getDualSolution(double[] duals)
Returns the sensitivity of the constraints and the variables. |
double |
getEpsb()
Returns the value that is used as a tolerance for the Right Hand Side (RHS) to determine whether a value should be considered as 0. |
double |
getEpsd()
Returns the value that is used as a tolerance for the reduced costs to determine whether a value should be considered as 0. |
double |
getEpsel()
Returns the value that is used as a tolerance for rounding values to zero. |
double |
getEpsint()
Returns the tolerance that is used to determine whether a floating-point number is in fact an integer |
double |
getEpsperturb()
Returns the value that is used as perturbation scalar for degenerative problems. |
double |
getEpspivot()
Returns the value that is used as a tolerance pivot element to determine whether a value should be considered as 0. |
int |
getImprove()
Returns the iterative improvement level. |
double |
getInfinite()
Returns the value of "infinite". |
void |
getLambda(double[] lambda)
Returns the Lamdba vectors (Lagrangian optimization). |
double |
getLowbo(int colnr)
Get the lower bound of a variable. |
long |
getLp()
Return the value of the lp attribute. |
int |
getLpIndex(int index)
Returns the index in the lp of the original row/column. |
java.lang.String |
getLpName()
Get the name of the problem. |
int |
getLrows()
Returns the number of Lagrangian rows in the lp. |
double |
getMat(int row,
int column)
Get a single element from the matrix. |
int |
getMaxLevel()
Returns the deepest Branch-and-bound level of the last solution. |
int |
getMaxpivot()
Returns the maximum number of pivots between a reinversion of the matrix. |
double |
getMipGap(boolean absolute)
Returns the MIP gap value. |
int |
getNameindex(java.lang.String name,
boolean isRow)
Gets the index of a given column or row name in the lp. |
int |
getNcolumns()
Returns the number of columns (variables) in the problem. |
double |
getNegrange()
Returns the negative value below which variables are split into a negative and a positive part. |
int |
getNonzeros()
Returns the number of non-zero elements in the matrix. |
int |
getNorigColumns()
Returns the number of original columns (variables) in the problem. |
int |
getNorigRows()
Returns the number of original rows (constraints) in the problem. |
int |
getNrows()
Returns the number of rows (constraints) in the problem. |
double |
getObjBound()
Returns initial "at least better than" guess for objective function. |
double |
getObjective()
Returns the value of the objective function. |
java.lang.String |
getOrigcolName(int colnr)
Gets the name of a column in the problem. |
int |
getOrigIndex(int index)
Returns the original row/column where a constraint/variable was before presolve. |
java.lang.String |
getOrigrowName(int rownr)
Gets the name of a constraint (row) in the problem. |
int |
getPivoting()
Returns the pivot rule. |
int |
getPresolve()
Returns the current presolve setting. |
int |
getPresolveloops()
Returns the number of times presolve is done. |
void |
getPrimalSolution(double[] pv)
Returns the solution of the model. |
int |
getPrintSol()
Returns a flag if all intermediate valid solutions must be printed while solving. |
double[] |
getPtrColumn(int columnrnr)
Get all column elements from the matrix. |
double[] |
getPtrConstraints()
Returns the values of the constraints. |
double[] |
getPtrDualSolution()
Returns the sensitivity of the constraints and the variables. |
double[] |
getPtrLambda()
Returns the Lamdba vectors (Lagrangian optimization). |
double[] |
getPtrPrimalSolution()
Returns the solution of the model. |
double[] |
getPtrRow(int rownr)
Get all row elements from the matrix. |
double[][] |
getPtrSensitivityObj()
Returns the sensitivity of the objective function. |
double[][] |
getPtrSensitivityObjex()
Returns the sensitivity of the objective function. |
double[][] |
getPtrSensitivityRhs()
Returns the sensitivity of the constraints and the variables. |
double[] |
getPtrVariables()
Returns the values of the variables. |
double |
getRh(int row)
Get the value of the right hand side (RHS) vector (column 0) for one row. |
double |
getRhRange(int rownr)
Gets the range on a constraint. |
void |
getRow(int rownr,
double[] row)
Get all row elements from the matrix. |
int |
getRowex(int rownr,
double[] row,
int[] nzcols)
Get the non-zero row elements from the matrix. |
java.lang.String |
getRowName(int rownr)
Gets the name of a constraint (row) in the problem. |
double |
getScalelimit()
Returns the relative scaling convergence criterion for the active scaling mode; the integer part specifies the maximum number of iterations. |
int |
getScaling()
Specifies which scaling algorithm is used. |
void |
getSensitivityObj(double[] objfrom,
double[] objtill)
Returns the sensitivity of the objective function. |
void |
getSensitivityObjex(double[] objfrom,
double[] objtill,
double[] objfromvalue,
double[] objtillvalue)
Returns the sensitivity of the objective function. |
void |
getSensitivityRhs(double[] duals,
double[] dualsfrom,
double[] dualstill)
Returns the sensitivity of the constraints and the variables. |
int |
getSimplextype()
Returns the desired combination of primal and dual simplex algorithms. |
int |
getSolutioncount()
Returns the number of equal solutions. |
int |
getSolutionlimit()
Returns the solution number that must be returned. |
int |
getStatus()
Returns an extra status after a call to a function. |
java.lang.String |
getStatustext(int statuscode)
Returns the description of a returncode of the solve function. |
long |
getTimeout()
Gets the timout. |
long |
getTotalIter()
Returns the total number of iterations with Branch-and-bound of the last solution. |
long |
getTotalNodes()
Returns the total number of nodes processed in branch-and-bound. |
double |
getUpbo(int colnr)
Get the upper bound of a variable. |
int |
getVarBranch(int colnr)
Returns, for the specified variable, which branch to take first in branch-and-bound algorithm. |
double |
getVarDualresult(int index)
Returns the sensitivity of the constraints and the variables. |
void |
getVariables(double[] var)
Returns the values of the variables. |
double |
getVarPrimalresult(int index)
Returns the solution of the model. |
int |
getVarPriority(int colnr)
Returns, for the specified variable, the priority the variable has in the branch-and-bound algorithm. |
int |
getVerbose()
Returns the verbose level. |
double |
getWorkingObjective()
Returns the value of the objective function. |
void |
guessBasis(double[] guessvector, int[] basisvector)
Guess a basis for the lp. |
boolean |
hasBFP()
Returns if there is a basis factorization package (BFP) available. |
boolean |
hasXLI()
Returns if there is an external language interface (XLI) set. |
boolean |
isAddRowmode()
Returns a flag which of the add routines perform best. |
boolean |
isAntiDegen(int testmask)
Returns if the degeneracy rule specified in testmask is active. |
boolean |
isBinary(int colnr)
Gets the type of the variable. |
boolean |
isBreakAtFirst()
Returns if the branch-and-bound algorithm stops at first found solution. |
boolean |
isConstrType(int row,
int mask)
Returns if constraint type specified in mask is active. |
boolean |
isDebug()
Returns a flag if all intermediate results and the branch-and-bound decisions must be printed while solving. |
boolean |
isFeasible(double[] values,
double threshold)
Checks if provided solution is a feasible solution. |
boolean |
isInfinite(double value)
Checks if the provided absolute of the value is larger or equal to "infinite". |
boolean |
isInt(int colnr)
Get the type of the variable. |
boolean |
isIntegerscaling()
Specifies which scaling algorithm is used. |
boolean |
isLagTrace()
Returns a flag if Lagrangian progression must be printed while solving. |
boolean |
isMaxim()
Returns objective function direction. |
boolean |
isNativeBFP()
Returns if the native (build-in) basis factorization package (BFP) is used, or an external package. |
boolean |
isNativeXLI()
Returns if a build-in External Language Interfaces (XLI) is available or not. |
boolean |
isNegative(int colnr)
Returns if the variable is negative. |
boolean |
isPivMode(int testmask)
Returns if pivot strategy specified in testmask is active. |
boolean |
isPivRule(int rule)
Checks if the specified pivot rule is active. |
boolean |
isPresolve(int testmask)
Returns if presolve level specified in testmask is active. |
boolean |
isScalemode(int testmask)
Returns if scaling mode specified in testmask is active. |
boolean |
isScaletype(int scaletype)
Returns if scaling type specified in scaletype is active. |
boolean |
isSemicont(int colnr)
Get the type of the variable. semi-continious or not. |
boolean |
isSOSVar(int colnr)
Returns if the variable is SOS or not. |
boolean |
isTrace()
Returns a flag if pivot selection must be printed while solving. |
boolean |
isUnbounded(int colnr)
Returns if the variable is free. |
boolean |
isUseNames(boolean isRow)
Returns if variable or constraint names are used. |
static VersionInfo |
lpSolveVersion()
Returns the full version number of the underlying lp_solve library. |
static LpSolve |
makeLp(int rows,
int columns)
Creates a new problem. |
void |
printConstraints(int columns)
Prints the values of the constraints of the lp. |
void |
printDebugdump(java.lang.String filename)
Do a generic readable data dump of key lp_solve model variables; principally for run difference and debugging purposes. |
void |
printDuals()
Prints the values of the duals of the lp. |
void |
printLp()
Prints the lp model. |
void |
printObjective()
Prints the objective value of the lp. |
void |
printScales()
Prints the scales of the lp. |
void |
printSolution(int columns)
Prints the solution (variables) of the lp. |
void |
printStr(java.lang.String str)
Prints a string. |
void |
printTableau()
Prints the tableau. |
void |
putAbortfunc(AbortListener listener,
java.lang.Object userhandle)
Register an AbortListener for callback. |
void |
putBbBranchfunc(BbListener listener,
java.lang.Object userhandle)
Register an BbBranchListener for callback. |
void |
putBbNodefunc(BbListener listener,
java.lang.Object userhandle)
Register an BbNodeListener for callback. |
void |
putLogfunc(LogListener listener,
java.lang.Object userhandle)
Register an LogListener for callback. |
void |
putMsgfunc(MsgListener listener,
java.lang.Object userhandle,
int mask)
Register an MsgListener for callback. |
java.lang.String |
readBasis(java.lang.String filename)
Read basis from a file and set as default basis. |
static LpSolve |
readFreeMps(java.lang.String filename,
int verbose)
Read a model in free MPS format from file and create a new problem. |
static LpSolve |
readLp(java.lang.String filename,
int verbose,
java.lang.String lpName)
Read an lp model from file and create a new problem. |
static LpSolve |
readMps(java.lang.String filename,
int verbose)
Read an mps model from file and create a new problem. |
void |
readParams(java.lang.String filename,
java.lang.String options)
Read settings from a parameter file. |
static LpSolve |
readXLI(java.lang.String xliname,
java.lang.String modelname,
java.lang.String dataname,
java.lang.String options,
int verbose)
Read a model via the External Language Interface and create a new problem. |
void |
resetBasis()
Resets the basis to the initial basis. |
void |
resetParams()
Resets parameters back to their default values. |
boolean |
resizeLp(int rows,
int columns)
Allocate memory for the specified size. |
boolean |
setAddRowmode(boolean turnon)
Specifies which add routine performs best. |
void |
setAntiDegen(int antiDegen)
Specifies if special handling must be done to reduce degeneracy/cycling while solving. |
void |
setBasis(int[] bascolumn,
boolean nonbasic)
Sets an initial basis of the lp. |
void |
setBasiscrash(int mode)
Specifies which basis crash mode must be used. |
int |
setBasisvar(int basisPos,
int enteringCol)
This is an internal function that has been published for special purposes. It should generally not be used. |
void |
setBbDepthlimit(int bbMaxlevel)
Sets the maximum branch-and-bound depth. |
void |
setBbFloorfirst(int floorFirst)
Specifies which branch to take first in branch-and-bound algorithm. |
void |
setBbRule(int bbRule)
Specifies the branch-and-bound rule. |
void |
setBFP(java.lang.String filename)
Set basis factorization package. |
void |
setBinary(int colnr,
boolean mustBeBin)
Set the type of the variable. |
void |
setBounds(int colnr,
double lower,
double upper)
Set the upper and lower bound of a variable. |
void |
setBoundsTighter(boolean tighten)
Specifies if set bounds may only be tighter or also less restrictive. |
void |
setBreakAtFirst(boolean breakAtFirst)
Specifies if the branch-and-bound algorithm stops at first found solution. |
void |
setBreakAtValue(double breakAtValue)
Specifies if the branch-and-bound algorithm stops when the object value is better than a given value. |
void |
setColName(int colnr,
java.lang.String name)
Set the name of a column in the problem. |
void |
setColumn(int colno,
double[] column)
Set a column in the lp. |
void |
setColumnex(int colno,
int count,
double[] column,
int[] rowno)
Set a column in the lp. |
void |
setConstrType(int rownr,
int constrType)
Set the type of a constraint. |
void |
setDebug(boolean debug)
Sets a flag if all intermediate results and the branch-and-bound decisions must be printed while solving. |
void |
setEpsb(double value)
Specifies the value that is used as a tolerance for the Right Hand Side (RHS) to determine whether a value should be considered as 0 |
void |
setEpsd(double value)
Specifies the value that is used as a tolerance for reduced costs to determine whether a value should be considered as 0. |
void |
setEpsel(double value)
Specifies the value that is used as a tolerance for rounding values to zero. |
void |
setEpsint(double value)
Specifies the tolerance that is used to determine whether a floating-point number is in fact an integer. |
void |
setEpslevel(int epslevel)
This is a simplified way of specifying multiple eps thresholds that are "logically" consistent. |
void |
setEpsperturb(double value)
Specifies the value that is used as perturbation scalar for degenerative problems. |
void |
setEpspivot(double value)
Specifies the value that is used as a tolerance pivot element to determine whether a value should be considered as 0. |
void |
setImprove(int improve)
Specifies the iterative improvement level. |
void |
setInfinite(double value)
Specifies the practical value for "infinite". |
void |
setInt(int colnr,
boolean mustBeInteger)
Set the type of the variable. |
void |
setLagTrace(boolean lagTrace)
Sets a flag if Lagrangian progression must be printed while solving. |
void |
setLowbo(int colnr,
double value)
Set the lower bound of a variable. |
void |
setLpName(java.lang.String name)
Set the name of the problem. |
void |
setMat(int row,
int column,
double value)
Set a single element in the matrix. |
void |
setMaxim()
Set objective function to maximize. |
void |
setMaxpivot(int maxNumInv)
Sets the maximum number of pivots between a reinversion of the matrix. |
void |
setMinim()
Set objective function to minimize. |
void |
setMipGap(boolean absolute,
double value)
Specifies the MIP gap value. |
void |
setNegrange(double negRange)
Set negative value below which variables are split into a negative and a positive part. |
void |
setObj(int column,
double value)
Set the objective function (row 0) of the matrix. |
void |
setObjBound(double objBound)
Set initial "at least better than" guess for objective function. |
void |
setObjFn(double[] row)
Set the objective function (row 0) of the matrix. |
void |
setObjFnex(int count,
double[] row,
int[] colno)
Set the objective function (row 0) of the matrix. |
void |
setOutputfile(java.lang.String filename)
Defines the output for the print_* functions. |
void |
setPivoting(int pivRule)
Specifies the pivot rule. |
void |
setPreferdual(boolean dodual)
Sets the desired combination of primal and dual simplex algorithms. |
void |
setPresolve(int doPresolve,
int maxloops)
Specifies if a presolve must be done before solving. |
void |
setPrintSol(int printSol)
Sets a flag if all intermediate valid solutions must be printed while solving. |
void |
setRh(int row,
double value)
Set the value of the right hand side (RHS) vector (column 0) for one row. |
void |
setRhRange(int rownr,
double range)
Set the range on a constraint. |
void |
setRhVec(double[] rh)
Set the right hand side (RHS) vector (column 0). |
void |
setRow(int rowno,
double[] row)
Set a constraint in the lp. |
void |
setRowex(int rowno,
int count,
double[] row,
int[] colno)
Set a constraint in the lp. |
void |
setRowName(int rownr,
java.lang.String name)
Set the name of a constraint (row) in the problem. |
void |
setScalelimit(double scalelimit)
Sets the relative scaling convergence criterion for the active scaling mode; the integer part specifies the maximum number of iterations. |
void |
setScaling(int scalemode)
Specifies which scaling algorithm must be used. |
void |
setSemicont(int colnr,
boolean mustBeSc)
Set the type of the variable. semi-continious or not. |
void |
setSense(boolean maximize)
Set objective function sense. |
void |
setSimplextype(int simplextype)
Sets the desired combination of primal and dual simplex algorithms. |
void |
setSolutionlimit(int limit)
Sets the solution number that must be returned. |
void |
setTimeout(long timeout)
Set a timeout. |
void |
setTrace(boolean trace)
Sets a flag if pivot selection must be printed while solving. |
void |
setUnbounded(int colnr)
Sets if the variable is free. |
void |
setUpbo(int colnr,
double value)
Set the upper bound of a variable. |
void |
setUseNames(boolean isRow,
boolean useNames)
Sets if variable or constraint names are used. |
void |
setVarBranch(int colnr,
int branchMode)
Specifies, for the specified variable, which branch to take first in branch-and-bound algorithm. |
void |
setVarWeights(double[] weights)
Set the weights on variables. |
void |
setVerbose(int verbose)
Set the verbose level. |
void |
setXLI(java.lang.String filename)
Set External Language Interfaces package. |
int |
solve()
Solve the model. |
void |
strAddColumn(java.lang.String column)
Add a column to the problem. |
void |
strAddConstraint(java.lang.String row,
int constrType,
double rh)
Add a constraint to the problem. |
void |
strAddLagCon(java.lang.String row,
int constrType,
double rh)
Add a Lagrangian constraint to the problem. |
void |
strSetObjFn(java.lang.String row)
Set the objective function (row 0) of the matrix. |
void |
strSetRhVec(java.lang.String rh)
Set the right hand side (RHS) vector (column 0). |
double |
timeElapsed()
Gets the time elapsed since start of solve. |
void |
unscale()
Unscales the model. |
void |
writeBasis(java.lang.String filename)
Writes current basis to a file. |
void |
writeFreeMps(java.lang.String filename)
Write a model in free MPS format to a file. |
void |
writeLp(java.lang.String filename)
Write an lp model to a file. |
void |
writeMps(java.lang.String filename)
Write an mps model to a file. |
void |
writeParams(java.lang.String filename,
java.lang.String options)
Write settings to a parameter file. |
void |
writeXLI(java.lang.String filename,
java.lang.String options,
boolean results)
Write a model to a file via the External Language Interface. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int FALSE
public static final int TRUE
public static final int AUTOMATIC
public static final int DYNAMIC
public static final int FR
public static final int LE
public static final int GE
public static final int EQ
public static final int OF
public static final int SIMPLEX_PRIMAL_PRIMAL
public static final int SIMPLEX_DUAL_PRIMAL
public static final int SIMPLEX_PRIMAL_DUAL
public static final int SIMPLEX_DUAL_DUAL
public static final int SIMPLEX_DEFAULT
public static final int PRESOLVE_NONE
public static final int PRESOLVE_ROWS
public static final int PRESOLVE_COLS
public static final int PRESOLVE_LINDEP
public static final int PRESOLVE_SOS
public static final int PRESOLVE_REDUCEMIP
public static final int PRESOLVE_KNAPSACK
public static final int PRESOLVE_ELIMEQ2
public static final int PRESOLVE_IMPLIEDFREE
public static final int PRESOLVE_REDUCEGCD
public static final int PRESOLVE_PROBEFIX
public static final int PRESOLVE_PROBEREDUCE
public static final int PRESOLVE_ROWDOMINATE
public static final int PRESOLVE_COLDOMINATE
public static final int PRESOLVE_MERGEROWS
public static final int PRESOLVE_IMPLIEDSLK
public static final int PRESOLVE_COLFIXDUAL
public static final int PRESOLVE_BOUNDS
public static final int PRESOLVE_DUALS
public static final int PRESOLVE_SENSDUALS
public static final int CRASH_NOTHING
public static final int CRASH_MOSTFEASIBLE
public static final int ANTIDEGEN_NONE
public static final int ANTIDEGEN_FIXEDVARS
public static final int ANTIDEGEN_COLUMNCHECK
public static final int ANTIDEGEN_STALLING
public static final int ANTIDEGEN_NUMFAILURE
public static final int ANTIDEGEN_LOSTFEAS
public static final int ANTIDEGEN_INFEASIBLE
public static final int ANTIDEGEN_DYNAMIC
public static final int ANTIDEGEN_DURINGBB
public static final int ANTIDEGEN_RHSPERTURB
public static final int ANTIDEGEN_BOUNDFLIP
public static final int NEUTRAL
public static final int CRITICAL
public static final int SEVERE
public static final int IMPORTANT
public static final int NORMAL
public static final int DETAILED
public static final int FULL
public static final int MSG_NONE
public static final int MSG_PRESOLVE
public static final int MSG_ITERATION
public static final int MSG_INVERT
public static final int MSG_LPFEASIBLE
public static final int MSG_LPOPTIMAL
public static final int MSG_LPEQUAL
public static final int MSG_LPBETTER
public static final int MSG_MILPFEASIBLE
public static final int MSG_MILPEQUAL
public static final int MSG_MILPBETTER
public static final int MSG_MILPSTRATEGY
public static final int MSG_MILPOPTIMAL
public static final int MSG_PERFORMANCE
public static final int MSG_INITPSEUDOCOST
public static final int IMPROVE_NONE
public static final int IMPROVE_SOLUTION
public static final int IMPROVE_DUALFEAS
public static final int IMPROVE_THETAGAP
public static final int IMPROVE_BBSIMPLEX
public static final int SCALE_NONE
public static final int SCALE_EXTREME
public static final int SCALE_RANGE
public static final int SCALE_MEAN
public static final int SCALE_GEOMETRIC
public static final int SCALE_CURTISREID
public static final int SCALE_LINEAR
public static final int SCALE_QUADRATIC
public static final int SCALE_LOGARITHMIC
public static final int SCALE_USERWEIGHT
public static final int SCALE_POWER2
public static final int SCALE_EQUILIBRATE
public static final int SCALE_INTEGERS
public static final int SCALE_DYNUPDATE
public static final int SCALE_ROWSONLY
public static final int SCALE_COLSONLY
public static final int PRICER_FIRSTINDEX
public static final int PRICER_DANTZIG
public static final int PRICER_DEVEX
public static final int PRICER_STEEPESTEDGE
public static final int PRICE_METHODDEFAULT
public static final int PRICE_PRIMALFALLBACK
public static final int PRICE_MULTIPLE
public static final int PRICE_PARTIAL
public static final int PRICE_ADAPTIVE
public static final int PRICE_HYBRID
public static final int PRICE_RANDOMIZE
public static final int PRICE_AUTOPARTIAL
public static final int PRICE_LOOPLEFT
public static final int PRICE_LOOPALTERNATE
public static final int PRICE_HARRISTWOPASS
public static final int PRICE_TRUENORMINIT
public static final int NODE_FIRSTSELECT
public static final int NODE_GAPSELECT
public static final int NODE_RANGESELECT
public static final int NODE_FRACTIONSELECT
public static final int NODE_PSEUDOCOSTSELECT
public static final int NODE_PSEUDONONINTSELECT
public static final int NODE_PSEUDORATIOSELECT
public static final int NODE_USERSELECT
public static final int NODE_WEIGHTREVERSEMODE
public static final int NODE_BRANCHREVERSEMODE
public static final int NODE_GREEDYMODE
public static final int NODE_PSEUDOCOSTMODE
public static final int NODE_DEPTHFIRSTMODE
public static final int NODE_RANDOMIZEMODE
public static final int NODE_DYNAMICMODE
public static final int NODE_RESTARTMODE
public static final int NODE_BREADTHFIRSTMODE
public static final int NODE_AUTOORDER
public static final int NODE_RCOSTFIXING
public static final int NODE_STRONGINIT
public static final int BRANCH_CEILING
public static final int BRANCH_FLOOR
public static final int BRANCH_AUTOMATIC
public static final int BRANCH_DEFAULT
public static final int UNKNOWNERROR
public static final int DATAIGNORED
public static final int NOBFP
public static final int NOMEMORY
public static final int NOTRUN
public static final int OPTIMAL
public static final int SUBOPTIMAL
public static final int INFEASIBLE
public static final int UNBOUNDED
public static final int DEGENERATE
public static final int NUMFAILURE
public static final int USERABORT
public static final int TIMEOUT
public static final int RUNNING
public static final int PRESOLVED
public static final int PROCFAIL
public static final int PROCBREAK
public static final int FEASFOUND
public static final int NOFEASFOUND
Method Detail |
public static LpSolve makeLp(int rows, int columns) throws LpSolveException
lprec
structure.
rows
- Initial number of rows.columns
- Initial number of columns.
LpSolveException
- if lp_solve could not create the problempublic static LpSolve readLp(java.lang.String filename, int verbose, java.lang.String lpName) throws LpSolveException
LpSolveException
public static LpSolve readMps(java.lang.String filename, int verbose) throws LpSolveException
LpSolveException
public static LpSolve readFreeMps(java.lang.String filename, int verbose) throws LpSolveException
LpSolveException
public static LpSolve readXLI(java.lang.String xliname, java.lang.String modelname, java.lang.String dataname, java.lang.String options, int verbose) throws LpSolveException
LpSolveException
public static VersionInfo lpSolveVersion()
protected void finalize() throws java.lang.Throwable
java.lang.Throwable
public long getLp()
public LpSolve copyLp() throws LpSolveException
LpSolveException
public void resizeLp(int rows, int columns) throws LpSolveException
public void setLpName(java.lang.String name) throws LpSolveException
LpSolveException
public java.lang.String getLpName() throws LpSolveException
LpSolveException
public void addConstraint(double[] row, int constrType, double rh) throws LpSolveException
LpSolveException
public void strAddConstraint(java.lang.String row, int constrType, double rh) throws LpSolveException
LpSolveException
public void addConstraintex(int count, double[] row, int[] colno, int constrType, double rh) throws LpSolveException
LpSolveException
public void delConstraint(int rownr) throws LpSolveException
LpSolveException
public boolean isConstrType(int row, int mask)
public void addLagCon(double[] row, int constrType, double rh) throws LpSolveException
LpSolveException
public void strAddLagCon(java.lang.String row, int constrType, double rh) throws LpSolveException
LpSolveException
public void addColumn(double[] column) throws LpSolveException
LpSolveException
public void addColumnex(int count, double[] column, int[] rowno) throws LpSolveException
LpSolveException
public void strAddColumn(java.lang.String column) throws LpSolveException
LpSolveException
public void delColumn(int columnnr) throws LpSolveException
LpSolveException
public void setRow(int rowno, double[] row) throws LpSolveException
LpSolveException
public void setRowex(int rowno, int count, double[] row, int[] colno) throws LpSolveException
LpSolveException
public void setColumn(int colno, double[] column) throws LpSolveException
LpSolveException
public void setColumnex(int colno, int count, double[] column, int[] rowno) throws LpSolveException
LpSolveException
public int columnInLp(double[] column)
public void setRowName(int rownr, java.lang.String name) throws LpSolveException
LpSolveException
public java.lang.String getRowName(int rownr) throws LpSolveException
LpSolveException
public java.lang.String getOrigrowName(int rownr) throws LpSolveException
LpSolveException
public void setColName(int colnr, java.lang.String name) throws LpSolveException
LpSolveException
public java.lang.String getColName(int colnr) throws LpSolveException
LpSolveException
public java.lang.String getOrigcolName(int colnr) throws LpSolveException
LpSolveException
public void setRhVec(double[] rh) throws LpSolveException
LpSolveException
public void strSetRhVec(java.lang.String rh) throws LpSolveException
LpSolveException
public void setRh(int row, double value) throws LpSolveException
LpSolveException
public double getRh(int row)
public void setConstrType(int rownr, int constrType) throws LpSolveException
LpSolveException
public short getConstrType(int rownr) throws LpSolveException
LpSolveException
public void addSOS(java.lang.String name, int sostype, int priority, int count, int[] sosvars, double[] weights) throws LpSolveException
LpSolveException
public boolean isSOSVar(int colnr) throws LpSolveException
LpSolveException
public void setObjFn(double[] row) throws LpSolveException
LpSolveException
public void strSetObjFn(java.lang.String row) throws LpSolveException
LpSolveException
public void setObjFnex(int count, double[] row, int[] colno) throws LpSolveException
LpSolveException
public void setObj(int column, double value) throws LpSolveException
LpSolveException
public void setMat(int row, int column, double value) throws LpSolveException
LpSolveException
public double getMat(int row, int column)
public void getRow(int rownr, double[] row) throws LpSolveException
LpSolveException
public int getRowex(int rownr, double[] row, int[] nzcols) throws LpSolveException
LpSolveException
public double[] getPtrRow(int rownr) throws LpSolveException
LpSolveException
public void getColumn(int colnr, double[] column) throws LpSolveException
LpSolveException
public int getColumnex(int colnr, double[] column, int[] nzrows) throws LpSolveException
LpSolveException
public double[] getPtrColumn(int columnrnr) throws LpSolveException
LpSolveException
public void setMaxim()
public void setMinim()
public void setSense(boolean maximize)
public boolean isMaxim()
public void setLowbo(int colnr, double value) throws LpSolveException
LpSolveException
public double getLowbo(int colnr) throws LpSolveException
LpSolveException
public void setUpbo(int colnr, double value) throws LpSolveException
LpSolveException
public double getUpbo(int colnr) throws LpSolveException
LpSolveException
public void setUnbounded(int colnr) throws LpSolveException
LpSolveException
public boolean isUnbounded(int colnr)
public boolean isNegative(int colnr)
public void setBounds(int colnr, double lower, double upper) throws LpSolveException
LpSolveException
public void setBoundsTighter(boolean tighten)
public boolean getBoundsTighter()
public void setRhRange(int rownr, double range) throws LpSolveException
LpSolveException
public double getRhRange(int rownr) throws LpSolveException
LpSolveException
public void setInt(int colnr, boolean mustBeInteger) throws LpSolveException
LpSolveException
public boolean isInt(int colnr)
public void setBinary(int colnr, boolean mustBeBin) throws LpSolveException
LpSolveException
public boolean isBinary(int colnr)
public void setSemicont(int colnr, boolean mustBeSc) throws LpSolveException
LpSolveException
public boolean isSemicont(int colnr)
public void setInfinite(double value)
public double getInfinite()
public boolean isInfinite(double value)
public void setEpsint(double value)
public double getEpsint()
public void setEpsb(double value)
public double getEpsb()
public void setEpsd(double value)
public double getEpsd()
public void setEpsel(double value)
public double getEpsel()
public void setEpspivot(double value)
public double getEpspivot()
public void setEpsperturb(double value)
public double getEpsperturb()
public void setEpslevel(int epslevel) throws LpSolveException
LpSolveException
public int getStatus()
public void setMipGap(boolean absolute, double value)
public double getMipGap(boolean absolute)
public void setVerbose(int verbose)
public int getVerbose()
public void setTimeout(long timeout)
public long getTimeout()
public double timeElapsed()
public void setPrintSol(int printSol)
public int getPrintSol()
public void setDebug(boolean debug)
public boolean isDebug()
public void setTrace(boolean trace)
public boolean isTrace()
public void setLagTrace(boolean lagTrace)
public boolean isLagTrace()
public boolean setAddRowmode(boolean turnon)
public boolean isAddRowmode()
public void setAntiDegen(int antiDegen)
public boolean isAntiDegen(int testmask)
public int getAntiDegen()
public void setPresolve(int doPresolve, int maxloops)
public boolean isPresolve(int testmask)
public int getPresolve()
public int getPresolveloops()
public void setMaxpivot(int maxNumInv)
public int getMaxpivot()
public void setBbRule(int bbRule)
public int getBbRule()
public void setBbDepthlimit(int bbMaxlevel)
public int getBbDepthlimit()
public int getSolutioncount()
public void setSolutionlimit(int limit)
public int getSolutionlimit()
public void setObjBound(double objBound)
public double getObjBound()
public void setBbFloorfirst(int floorFirst)
public int getBbFloorfirst()
public void setVarBranch(int colnr, int branchMode) throws LpSolveException
LpSolveException
public int getVarBranch(int colnr) throws LpSolveException
LpSolveException
public void setVarWeights(double[] weights) throws LpSolveException
LpSolveException
public int getVarPriority(int colnr) throws LpSolveException
LpSolveException
public void setBreakAtFirst(boolean breakAtFirst)
public boolean isBreakAtFirst()
public void setBreakAtValue(double breakAtValue)
public double getBreakAtValue()
public void setScaling(int scalemode)
public int getScaling()
public boolean isScalemode(int testmask)
public boolean isScaletype(int scaletype)
public boolean isIntegerscaling()
public void setScalelimit(double scalelimit)
public double getScalelimit()
public void setImprove(int improve)
public int getImprove()
public void setPivoting(int pivRule)
public int getPivoting()
public boolean isPivMode(int testmask)
public boolean isPivRule(int rule)
public void setPreferdual(boolean dodual)
public void setSimplextype(int simplextype)
public int getSimplextype()
public void setNegrange(double negRange)
public double getNegrange()
public long getTotalIter()
public int getMaxLevel()
public long getTotalNodes()
public int getNrows()
public int getNorigRows()
public int getLrows()
public int getNcolumns()
public int getNorigColumns()
public int getNonzeros()
public int getOrigIndex(int index)
public int getLpIndex(int index)
public void setBasis(int[] bascolumn, boolean nonbasic) throws LpSolveException
LpSolveException
public void getBasis(int[] bascolumn, boolean nonbasic) throws LpSolveException
LpSolveException
public void resetBasis()
public void defaultBasis()
public void setBasiscrash(int mode)
public int getBasiscrash()
public void guessBasis(double[] guessvector, int[] basisvector) throws LpSolveException
LpSolveException
public void unscale()
public void setBFP(java.lang.String filename) throws LpSolveException
LpSolveException
public boolean isNativeBFP()
public boolean hasBFP()
public int solve() throws LpSolveException
LpSolveException
public java.lang.String getStatustext(int statuscode)
public boolean isFeasible(double[] values, double threshold) throws LpSolveException
LpSolveException
public double getObjective() throws LpSolveException
LpSolveException
public double getWorkingObjective() throws LpSolveException
LpSolveException
public void getVariables(double[] var) throws LpSolveException
LpSolveException
public double[] getPtrVariables() throws LpSolveException
LpSolveException
public void getConstraints(double[] var) throws LpSolveException
LpSolveException
public double[] getPtrConstraints() throws LpSolveException
LpSolveException
public void getPrimalSolution(double[] pv) throws LpSolveException
LpSolveException
public double[] getPtrPrimalSolution() throws LpSolveException
LpSolveException
public double getVarPrimalresult(int index) throws LpSolveException
LpSolveException
public void getSensitivityRhs(double[] duals, double[] dualsfrom, double[] dualstill) throws LpSolveException
LpSolveException
public double[][] getPtrSensitivityRhs() throws LpSolveException
LpSolveException
public void getDualSolution(double[] duals) throws LpSolveException
LpSolveException
public double[] getPtrDualSolution() throws LpSolveException
LpSolveException
public double getVarDualresult(int index) throws LpSolveException
LpSolveException
public void getSensitivityObj(double[] objfrom, double[] objtill) throws LpSolveException
LpSolveException
public double[][] getPtrSensitivityObj() throws LpSolveException
LpSolveException
public void getSensitivityObjex(double[] objfrom, double[] objtill, double[] objfromvalue, double[] objtillvalue) throws LpSolveException
LpSolveException
public double[][] getPtrSensitivityObjex() throws LpSolveException
LpSolveException
public void getLambda(double[] lambda) throws LpSolveException
LpSolveException
public double[] getPtrLambda() throws LpSolveException
LpSolveException
public void deleteLp()
public void writeLp(java.lang.String filename) throws LpSolveException
LpSolveException
public void writeMps(java.lang.String filename) throws LpSolveException
LpSolveException
public void writeFreeMps(java.lang.String filename) throws LpSolveException
LpSolveException
public java.lang.String readBasis(java.lang.String filename) throws LpSolveException
LpSolveException
public void writeBasis(java.lang.String filename) throws LpSolveException
LpSolveException
public void readParams(java.lang.String filename, java.lang.String options) throws LpSolveException
LpSolveException
public void writeParams(java.lang.String filename, java.lang.String options) throws LpSolveException
LpSolveException
public void resetParams()
public void printLp()
public void printConstraints(int columns)
public void printDuals()
public void printScales()
public void printTableau()
public void printObjective()
public void printSolution(int columns)
public void printStr(java.lang.String str)
public void setOutputfile(java.lang.String filename) throws LpSolveException
LpSolveException
public void printDebugdump(java.lang.String filename) throws LpSolveException
LpSolveException
public void setXLI(java.lang.String filename) throws LpSolveException
LpSolveException
public void writeXLI(java.lang.String filename, java.lang.String options, boolean results) throws LpSolveException
LpSolveException
public boolean hasXLI()
public boolean isNativeXLI()
public int getNameindex(java.lang.String name, boolean isRow)
public void dualizeLp() throws LpSolveException
LpSolveException
public boolean isUseNames(boolean isRow)
public void setUseNames(boolean isRow, boolean useNames)
public double getConstrValue(int rownr, int count, double[] primsolution, int[] nzindex)
public int setBasisvar(int basisPos, int enteringCol)
public void putAbortfunc(AbortListener listener, java.lang.Object userhandle) throws LpSolveException
AbortListener
for callback.
listener
- the listener that should be called by lp_solveuserhandle
- an arbitrary object that is passed to the listener on call
LpSolveException
public void putLogfunc(LogListener listener, java.lang.Object userhandle) throws LpSolveException
LogListener
for callback.
listener
- the listener that should be called by lp_solveuserhandle
- an arbitrary object that is passed to the listener on call
LpSolveException
public void putMsgfunc(MsgListener listener, java.lang.Object userhandle, int mask) throws LpSolveException
MsgListener
for callback.
listener
- the listener that should be called by lp_solveuserhandle
- an arbitrary object that is passed to the listener on call
LpSolveException
public void putBbBranchfunc(BbListener listener, java.lang.Object userhandle) throws LpSolveException
BbBranchListener
for callback.
listener
- the listener that should be called by lp_solveuserhandle
- an arbitrary object that is passed to the listener on call
LpSolveException
public void putBbNodefunc(BbListener listener, java.lang.Object userhandle) throws LpSolveException
BbNodeListener
for callback.
listener
- the listener that should be called by lp_solveuserhandle
- an arbitrary object that is passed to the listener on call
LpSolveException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Throwable
java.lang.Exception
lpsolve.LpSolveException
Exception thrown by the native methods in the C stub DLL.
Field Summary |
Fields inherited from class java.lang.Exception |
|
Constructor Summary | |
LpSolveException()
|
|
LpSolveException(java.lang.String arg0)
|
Methods inherited from class java.lang.Throwable |
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public LpSolveException()
public LpSolveException(java.lang.String arg0)
arg0
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Classes that implement this interface may be passed
to the putMsgfunc
method of the LpSolve
class.
LpSolve.putMsgfunc(lpsolve.MsgListener, java.lang.Object, int)
,
"lp_solve documentation for 'put_msgfunc'"Method Summary | |
void |
msgfunc(LpSolve problem,
java.lang.Object userhandle,
int msg)
This routine is called when a situation specified in the mask parameter of putMsgfunc occurs. |
Method Detail |
public void msgfunc(LpSolve problem, java.lang.Object userhandle, int msg) throws LpSolveException
problem
- the problem this Listener was defined foruserhandle
- the userhandle object that was passed to putMsgfunc
msg
- event code why this method was called
LpSolveException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
AbortListener | Classes that implement this interface may be passed
to the putAbortfunc method of the LpSolve class. |
BbListener | Classes that implement this interface may be passed
to the putbbBranchfunc and putbbNodefunc method
of the LpSolve class. |
LogListener | Classes that implement this interface may be passed
to the putLogfunc method of the LpSolve class. |
MsgListener | Classes that implement this interface may be passed
to the putMsgfunc method of the LpSolve class. |
Class Summary | |
LpSolve | Object wrapper for a problem structure of the lp_solve library. |
VersionInfo | Contains the full version info for a lp_solve library instance. |
Exception Summary | |
LpSolveException | Exception thrown by the native methods in the C stub DLL. |
This package contains the files for the Java wrapper for the lp_solve optimization library. See the file README.html in the root direcory of the distribution archive for details.
|
|||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectlpsolve.VersionInfo
Contains the full version info for a lp_solve library instance.
Constructor Summary | |
VersionInfo(int major,
int minor,
int release,
int build)
Creates a new instance of this class |
Method Summary | |
int |
getBuild()
|
int |
getMajorversion()
|
int |
getMinorversion()
|
int |
getRelease()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public VersionInfo(int major, int minor, int release, int build)
Method Detail |
public int getBuild()
public int getMajorversion()
public int getMinorversion()
public int getRelease()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Classes that implement this interface may be passed
to the putbbBranchfunc
and putbbNodefunc
method
of the LpSolve
class.
LpSolve.putBbBranchfunc(lpsolve.BbListener, java.lang.Object)
,
LpSolve.putBbNodefunc(lpsolve.BbListener, java.lang.Object)
,
"lp_solve documentation for 'put_bb_branchfunc'",
"lp_solve documentation for 'put_bb_nodefunc'"Method Summary | |
int |
bbfunc(LpSolve problem,
java.lang.Object userhandle,
int message)
TODO: add documentation when available |
Method Detail |
public int bbfunc(LpSolve problem, java.lang.Object userhandle, int message) throws LpSolveException
problem
- the problem this Listener was defined foruserhandle
- the userhandle object that was passed to putLogfunc
LpSolveException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
putAbortfunc
method of the LpSolve
class.putbbBranchfunc
and putbbNodefunc
method
of the LpSolve
class.putLogfunc
method of the LpSolve
class.putMsgfunc
method of the LpSolve
class.AbortListener
for callback.
BbBranchListener
for callback.
BbNodeListener
for callback.
LogListener
for callback.
MsgListener
for callback.
|
|||||||||
PREV NEXT | FRAMES NO FRAMES |
This file contains a reference for all methods in the lp_solve library and the Java wrapper. The first column of the following table contains the C functions of the lp_solve library, the second column the corresponding methods of the Java wrapper.
C function | Java wrapper method (LpSolve class) |
---|---|
unsigned char add_column (lprec* lp, REAL* column) | void addColumn(double[] column) throws LpSolveException |
unsigned char add_columnex (lprec* lp, int count, REAL* column, int* rowno) | void addColumnex(int count, double[] column, int[] rowno) throws LpSolveException |
unsigned char add_constraint (lprec* lp, REAL *row, int constr_type, REAL rh) | void addConstraint(double[] row, int constrType, double rh) throws LpSolveException |
unsigned char add_constraintex (lprec *lp, int count, REAL *row, int *colno, int constr_type, REAL rh) | void addConstraintex(int count, double[] row, int[] colno, int constrType, double rh) throws LpSolveException |
unsigned char add_lag_con (lprec* lp, REAL *row, int con_type, REAL rhs) | void addLagCon(double[] row, int constrType, double rh) throws LpSolveException |
int add_SOS (lprec* lp, char *name, int sostype, int priority, int count, int *sosvars, REAL *weights) | void addSOS(String name, int sostype, int priority, int count, int[] sosvars, double[] weights) throws LpSolveException |
int column_in_lp (lprec* lp, REAL *column) | int columnInLp(double[] column) |
void default_basis (lprec* lp) | void defaultBasis() |
unsigned char del_column(lprec *lp, int column) | void delColumn(int columnnr) throws LpSolveException |
unsigned char del_constraint(lprec *lp, int del_row) | void delConstraint(int rownr) throws LpSolveException |
void delete_lp(lprec *lp) | void deleteLp() |
void free_lp(lprec **plp) | <Not implemented, use deleteLp() instead> |
int get_anti_degen(lprec *lp) | int getAntiDegen() |
void get_basis(lprec *lp, int *bascolumn, unsigned char nonbasic) | void getBasis(int[] bascolumn, boolean nonbasic) |
int get_basiscrash(lprec *lp) | int getBasiscrash() |
int get_bb_depthlimit(lprec *lp) | int getBbDepthlimit() |
int get_bb_floorfirst(lprec *lp) | int getBbFloorfirst() |
int get_bb_rule(lprec *lp) | int getBbRule() |
unsigned char get_bounds_tighter(lprec *lp) | boolean getBoundsTighter() |
REAL get_break_at_value(lprec *lp) | double getBreakAtValue() |
char *get_col_name(lprec *lp, int column) | String getColName(int colnr) throws LpSolveException |
unsigned char get_column(lprec *lp, int col_nr, REAL *column) | void getColumn(int columnrnr, double[] column) throws LpSolveException |
<Not implemented> | double[] getPtrColumn(int columnrnr) throws LpSolveException |
int get_constr_type(lprec *lp, int row) | short getConstrType(int rownr) throws LpSolveException |
unsigned char get_constraints(lprec *lp, REAL *constr) | void getConstraints(double[] var) throws LpSolveException |
unsigned char get_dual_solution(lprec *lp, REAL *duals) | void getDualSolution(double[] duals) throws LpSolveException |
REAL get_epsb(lprec *lp) | double getEpsb() |
REAL get_epsd(lprec *lp) | double getEpsd() |
REAL get_epsel(lprec *lp) | double getEpsel() |
REAL get_epsint(lprec *lp) | double getEpsint() |
REAL get_epsperturb(lprec *lp) | double getEpsperturb() |
REAL get_epspivot(lprec *lp) | double getEpspivot() |
int get_improve(lprec *lp) | int getImprove() |
REAL get_infinite(lprec *lp) | double getInfinite() |
unsigned char get_lambda(lprec *lp, REAL *lambda) | void getLambda(double[] lambda) throws LpSolveException |
REAL get_lowbo(lprec *lp, int column) | double getLowbo(int colnr) throws LpSolveException |
int get_lp_index(lprec *lp, int orig_index) | int getLpIndex(int index) |
char *get_lp_name(lprec *lp) | String getLpName() throws LpSolveException |
int get_Lrows(lprec *lp) | int getLrows() |
REAL get_mat(lprec *lp, int row, int column) | double getMat(int row, int column) |
int get_max_level(lprec *lp) | int getMaxLevel() |
int get_maxpivot(lprec *lp) | int getMaxpivot() |
REAL get_mip_gap(lprec *lp, unsigned char absolute) | double getMipGap(boolean absolute) |
int get_Ncolumns(lprec *lp) | int getNcolumns() |
REAL get_negrange(lprec *lp) | double getNegrange() |
int get_nonzeros(lprec *lp) | int getNonzeros() |
int get_Norig_columns(lprec *lp) | int getNorigColumns() |
int get_Norig_rows(lprec *lp) | int getNorigRows() |
int get_Nrows(lprec *lp) | int getNrows() |
REAL get_obj_bound(lprec *lp) | double getObjBound() |
REAL get_objective(lprec *lp) | getObjective() |
int get_orig_index(lprec *lp, int lp_index) | int getOrigIndex(int index) |
char *get_origcol_name(lprec *lp, int column) | String getOrigcolName(int colnr) throws LpSolveException |
char *get_origrow_name(lprec *lp, int row) | String getOrigrowName(int rownr) throws LpSolveException |
int get_pivoting(lprec *lp) | int getPivoting() |
int get_presolve(lprec *lp) | int getPresolve() |
unsigned char get_primal_solution(lprec *lp, REAL *pv) | void getPrimalSolution(double[] pv) throws LpSolveException |
int get_print_sol(lprec *lp) | int getPrintSol() |
unsigned char get_ptr_constraints(lprec *lp, REAL **ptr_constr) | double[] getPtrConstraints() throws LpSolveException |
unsigned char get_ptr_dual_solution(lprec *lp, REAL **ptr_duals) | double[] getPtrDualSolution() throws LpSolveException |
unsigned char get_ptr_lambda(lprec *lp, REAL **ptr_lambda) | double[] getPtrLambda() throws LpSolveException |
unsigned char get_ptr_primal_solution(lprec *lp, REAL **ptr_pv) | double[] getPtrPrimalSolution() throws LpSolveException |
unsigned char get_ptr_sensitivity_obj(lprec *lp, REAL **ptr_objfrom, REAL **ptr_objtill) | double[][] getPtrSensitivityObj() throws LpSolveException |
unsigned char get_ptr_sensitivity_objex(lprec *lp, REAL **ptr_objfrom, REAL **ptr_objtill, REAL *ptr_objfromvalue, REAL *ptr_objtillvalue) | double[][] getPtrSensitivityObjex() throws LpSolveException |
unsigned char get_ptr_sensitivity_rhs(lprec *lp, REAL **ptr_duals, REAL **ptr_dualsfrom, REAL **ptr_dualstill) | double[][] getPtrSensitivityRhs() throws LpSolveException |
unsigned char get_ptr_variables(lprec *lp, REAL **ptr_var) | double[] getPtrVariables() throws LpSolveException |
REAL get_rh(lprec *lp, int row) | double getRh(int row) |
REAL get_rh_range(lprec *lp, int row) | double getRhRange(int rownr) throws LpSolveException |
unsigned char get_row(lprec *lp, int row_nr, REAL *row) | void getRow(int rownr, double[] row) throws LpSolveException |
<Not implemented> | double[] getPtrRow(int rownr) throws LpSolveException |
char *get_row_name(lprec *lp, int row) | String getRowName(int rownr) throws LpSolveException |
REAL get_scalelimit(lprec *lp) | double getScalelimit() |
int get_scaling(lprec *lp) | int getScaling() |
unsigned char get_sensitivity_obj(lprec *lp, REAL *objfrom, REAL *objtill) | void getSensitivityObj(double[] objfrom, double[] objtill) throws LpSolveException |
unsigned char get_sensitivity_objex(lprec *lp, REAL *objfrom, REAL *objtill, REAL *objfromvalue, REAL *objtillvalue) | void getSensitivityObjex(double[] objfrom, double[] objtill, double[] objfromvalue, double[] objtillvalue) throws LpSolveException |
unsigned char get_sensitivity_rhs(lprec *lp, REAL *duals, REAL *dualsfrom, REAL *dualstill) | void getSensitivityRhs(double[] duals, double[] dualsfrom, double[] dualstill) throws LpSolveException |
int get_simplextype(lprec *lp) | int getSimplextype() |
int get_solutioncount(lprec *lp) | int getSolutioncount() |
int get_solutionlimit(lprec *lp) | int getSolutionlimit() |
int get_status(lprec *lp) | int getStatus() |
char *get_statustext(lprec *lp, int statuscode) | String getStatustext(int statuscode) |
long get_timeout(lprec *lp) | long getTimeout() |
int get_total_iter(lprec *lp) | int getTotalIter() |
int get_total_nodes(lprec *lp) | int getTotalNodes() |
REAL get_upbo(lprec *lp, int column) | double getUpbo(int colnr) throws LpSolveException |
int get_var_branch(lprec *lp, int column) | int getVarBranch(int colnr) throws LpSolveException |
REAL get_var_dualresult(lprec *lp, int index) | double getVarDualresult(int index) throws LpSolveException |
REAL get_var_primalresult(lprec *lp, int index) | double getVarPrimalresult(int index) throws LpSolveException |
int get_var_priority(lprec *lp, int column) | int getVarPriority(int colnr) throws LpSolveException |
unsigned char get_variables(lprec *lp, REAL *var) | void getVariables(double[] var) throws LpSolveException |
int get_verbose(lprec *lp) | int getVerbose() |
REAL get_working_objective(lprec *lp) | double getWorkingObjective() throws LpSolveException |
unsigned char guess_basis(lprec *lp, double *guessvector, int *basisvector) | void guessBasis(double[] guessvector, int[] basisvector) throws LpSolveException |
unsigned char has_BFP(lprec *lp) | boolean hasBFP() |
unsigned char has_XLI(lprec *lp) | boolean hasXLI() |
unsigned char is_add_rowmode(lprec *lp) | boolean isAddRowmode() |
unsigned char is_anti_degen(lprec *lp, int testmask) | boolean isAntiDegen(int testmask) |
unsigned char is_binary(lprec *lp, int column) | boolean isBinary(int colnr) |
unsigned char is_break_at_first(lprec *lp) | boolean isBreakAtFirst() |
unsigned char is_constr_type(lprec *lp, int row, int mask) | boolean isConstrType(int row, int mask) |
unsigned char is_debug(lprec *lp) | boolean isDebug() |
unsigned char is_feasible(lprec *lp, REAL *values, REAL threshold) | boolean isFeasible(double[] values, double threshold) throws LpSolveException |
unsigned char is_free(lprec *lp, int column) | boolean isFree(int colnr) |
unsigned char is_infinite(lprec *lp, REAL value) | boolean isInfinite(double value) |
unsigned char is_int(lprec *lp, int column) | boolean isInt(int colnr) |
unsigned char is_integerscaling(lprec *lp) | boolean isIntegerscaling() |
unsigned char is_lag_trace(lprec *lp) | boolean isLagTrace() |
unsigned char is_maxim(lprec *lp) | boolean isMaxim() |
unsigned char is_nativeBFP(lprec *lp) | boolean isNativeBFP() |
unsigned char is_nativeXLI(lprec *lp) | boolean isNativeXLI() |
unsigned char is_negative(lprec *lp, int column) | boolean isNegative(int colnr) |
unsigned char is_piv_mode(lprec *lp, int testmask) | boolean isPivMode(int testmask) |
unsigned char is_piv_rule(lprec *lp, int rule) | boolean isPivRule(int rule) |
unsigned char is_presolve(lprec *lp, int testmask) | boolean isPresolve(int testmask) |
unsigned char is_scalemode(lprec *lp, int testmask) | boolean isScalemode(int testmask) |
unsigned char is_scaletype(lprec *lp, int scaletype) | boolean isScaletype(int scaletype) |
unsigned char is_semicont(lprec *lp, int column) | boolean isSemicont(int colnr) |
unsigned char is_SOS_var(lprec *lp, int column) | boolean isSOSVar(int colnr) throws LpSolveException |
unsigned char is_trace(lprec *lp) | boolean isTrace() |
int lag_solve(lprec *lp, REAL start_bound, int num_iter, short verbose) | <Function is currently not exported from lp_solve dll> |
void lp_solve_version(int *majorversion, int *minorversion, int *release, int *build) | static VersionInfo lpSolveVersion() |
lprec *make_lp(int rows, int columns) | static LpSolve makeLp(int rows, int columns) throws LpSolveException |
void print_constraints(lprec *lp, int columns) | void printConstraints(int columns) |
unsigned char print_debugdump(lprec *lp, char *filename) | void printDebugdump(String filename) throws LpSolveException |
void print_duals(lprec *lp) | void printDuals() |
void print_lp(lprec *lp) | void printLp() |
void print_objective(lprec *lp) | void printObjective() |
void print_scales(lprec *lp) | void printScales() |
void print_solution(lprec *lp, int columns) | void printSolution(int columns) |
void print_str(lprec *lp, char *str) | void printStr(String str) |
void print_tableau(lprec *lp) | void printTableau() |
void put_abortfunc(lprec *lp, ctrlcfunc newctrlc, void *ctrlchandle) | void putAbortfunc(AbortListener listener, Object userhandle) throws LpSolveException |
void put_logfunc(lprec *lp, logfunc newlog, void *loghandle) | void putLogfunc(LogListener listener, Object userhandle) throws LpSolveException |
void put_msgfunc(lprec *lp, msgfunc newmsg, void *msghandle, int mask) | void putMsgfunc(MsgListener listener, Object userhandle, int mask) throws LpSolveException |
lprec *read_freeMPS(char *filename, int options) | static LpSolve readFreeMps(String filename, int options) throws LpSolveException |
lprec *read_freemps(FILE *stream, int options) | <Not implemented, use readFreeMps instead> |
lprec *read_lp(FILE *stream, int verbose, char *lp_name) | <Not implemented, use readLp instead> |
lprec *read_LP(char *filename, int verbose, char *lp_name) | static LpSolve readLp(String filename, int verbose, String lpName) throws LpSolveException |
lprec *read_lpt(FILE *stream, int verbose, char *lp_name) | <Not implemented, use readLpt instead> |
lprec *read_LPT(char *filename, int verbose, char *lp_name) | static LpSolve readLpt(String filename, int verbose, String lpName) throws LpSolveException |
lprec *read_mps(FILE *stream, int options) | <Not implemented, use readMps instead> |
lprec *read_MPS(char *filename, int options) | static LpSolve readMps(String filename, int options) throws LpSolveException |
lprec *read_XLI(char *xliname, char *modelname, char *dataname, char *options, int verbose) | static LpSolve readXLI(String xliname, String modelname, String dataname, String options, int verbose) throws LpSolveException |
void reset_basis(lprec *lp) | void resetBasis() |
unsigned char resize_lp(lprec *lp, int rows, int columns) | void resizeLp(int rows, int columns) throws LpSolveException |
unsigned char set_add_rowmode(lprec *lp, unsigned char turnon) | boolean setAddRowmode(boolean turnon) |
void set_anti_degen(lprec *lp, int anti_degen) | void setAntiDegen(int antiDegen) |
unsigned char set_basis(lprec *lp, int *bascolumn, unsigned char nonbasic) | void setBasis(int[] bascolumn, boolean nonbasic) throws LpSolveException |
void set_basiscrash(lprec *lp, int mode) | void setBasiscrash(int mode) |
void set_bb_depthlimit(lprec *lp, int bb_maxlevel) | void setBbDepthlimit(int bbMaxlevel) |
void set_bb_floorfirst(lprec *lp, int bb_floorfirst) | void setBbFloorfirst(int floorFirst) |
void set_bb_rule(lprec *lp, int bb_rule) | void setBbRule(int bbRule) |
unsigned char set_BFP(lprec *lp, char *filename) | void setBFP(String filename) throws LpSolveException |
unsigned char set_XLI(lprec *lp, char *filename) | void setXLI(String filename) throws LpSolveException |
unsigned char set_binary(lprec *lp, int column, unsigned char must_be_bin) | void setBinary(int colnr, boolean mustBeBin) throws LpSolveException |
unsigned char set_bounds(lprec *lp, int column, REAL lower, REAL upper) | void setBounds(int colnr, double lower, double upper) throws LpSolveException |
void set_bounds_tighter(lprec *lp, unsigned char tighten) | void setBoundsTighter(boolean tighten) |
void set_break_at_first(lprec *lp, unsigned char break_at_first) | void setBreakAtFirst(boolean breakAtFirst) |
void set_break_at_value(lprec *lp, REAL break_at_value) | void setBreakAtValue(double breakAtValue) |
unsigned char set_col_name(lprec *lp, int column, char *new_name) | void setColName(int colnr, String name) throws LpSolveException |
unsigned char set_column(lprec *lp, int col_no, REAL *column) | void setColumn(int colno, double[] column) throws LpSolveException |
unsigned char set_columnex(lprec *lp, int col_no, int count, REAL *column, int *rowno) | void setColumnex(int colno, int count, double[] column, int[] rowno) throws LpSolveException |
unsigned char set_constr_type(lprec *lp, int row, int con_type) | void setConstrType(int rownr, int constrType) throws LpSolveException |
void set_debug(lprec *lp, unsigned char debug) | void setDebug(boolean debug) |
void set_epsb(lprec *lp, REAL epsb) | void setEpsb(double value) |
void set_epsd(lprec *lp, REAL epsd) | void setEpsd(double value) |
void set_epsel(lprec *lp, REAL epsel) | void setEpsel(double value) |
void set_epsint(lprec *lp, REAL epsint) | void setEpsint(double value) |
void set_epsperturb(lprec *lp, REAL epsperturb) | void setEpsperturb(double value) |
void set_epspivot(lprec *lp, REAL epspivot) | void setEpspivot(double value) |
unsigned char set_free(lprec *lp, int column) | void setFree(int colnr) throws LpSolveException |
void set_improve(lprec *lp, int improve) | void setImprove(int improve) |
void set_infinite(lprec *lp, REAL infinite) | void setInfinite(double value) |
unsigned char set_int(lprec *lp, int column, unsigned char must_be_int) | void setInt(int colnr, boolean mustBeInteger) throws LpSolveException |
void set_lag_trace(lprec *lp, unsigned char lag_trace) | void setLagTrace(boolean lagTrace) |
unsigned char set_lowbo(lprec *lp, int column, REAL value) | void setLowbo(int colnr, double value) throws LpSolveException |
unsigned char set_lp_name(lprec *lp, char *lpname) | void setLpName(String name) throws LpSolveException |
unsigned char set_mat(lprec *lp, int row, int column, REAL value) | void setMat(int row, int column, double value) throws LpSolveException |
void set_maxim(lprec *lp) | void setMaxim() |
void set_maxpivot(lprec *lp, int max_num_inv) | void setMaxpivot(int maxNumInv) |
void set_minim(lprec *lp) | void setMinim() |
void set_mip_gap(lprec *lp, unsigned char absolute, REAL mip_gap) | void setMipGap(boolean absolute, double value) |
void set_negrange(lprec *lp, REAL negrange) | void setNegrange(double negRange) |
void set_obj_bound(lprec *lp, REAL obj_bound) | void setObjBound(double objBound) |
unsigned char set_obj_fn(lprec *lp, REAL *row) | void setObjFn(double[] row) throws LpSolveException |
unsigned char set_obj_fnex(lprec *lp, int count, REAL *row, int *colno) | void setObjFnex(int count, double[] row, int[] colno) throws LpSolveException |
unsigned char set_obj(lprec *lp, int column, REAL value) | void setObj(int column, double value) throws LpSolveException |
void set_outputstream(lprec *lp, FILE *stream) | <Not implemented, use setOutputfile instead> |
unsigned char set_outputfile(lprec *lp, char *filename) | void setOutputfile(String filename) throws LpSolveException |
void set_pivoting(lprec *lp, int pivoting) | void setPivoting(int pivRule) |
void set_preferdual(lprec *lp, unsigned char dodual) | void setPreferdual(int dodual) |
void set_presolve(lprec *lp, int do_presolve) | void setPresolve(int doPresolve) |
void set_print_sol(lprec *lp, int print_sol) | void setPrintSol(int printSol) |
unsigned char set_rh(lprec *lp, int row, REAL value) | void setRh(int row, double value) throws LpSolveException |
unsigned char set_rh_range(lprec *lp, int row, REAL deltavalue) | void setRhRange(int rownr, double range) throws LpSolveException |
void set_rh_vec(lprec *lp, REAL *rh) | void setRhVec(double[] rh) throws LpSolveException |
unsigned char set_row(lprec *lp, int row_no, REAL *row) | void setRow(int rowno, double[] row) throws LpSolveException |
unsigned char set_rowex(lprec *lp, int row_no, int count, REAL *row, int *colno) | void setRowex(int rowno, int count, double[] row, int[] colno) throws LpSolveException |
unsigned char set_row_name(lprec *lp, int row, char *new_name) | void setRowName(int rownr, String name) throws LpSolveException |
void set_scalelimit(lprec *lp, REAL scalelimit) | void setScalelimit(double scalelimit) |
void set_scaling(lprec *lp, int scalemode) | void setScaling(int scalemode) |
unsigned char set_semicont(lprec *lp, int column, unsigned char must_be_sc) | void setSemicont(int colnr, boolean mustBeSc) throws LpSolveException |
void set_sense(lprec *lp, unsigned char maximize) | void setSense(boolean maximize) |
void set_simplextype(lprec *lp, int simplextype) | void setSimplextype(int simplextype) |
void set_solutionlimit(lprec *lp, int limit) | void setSolutionlimit(int limit) |
void set_timeout(lprec *lp, long sectimeout) | void setTimeout(long timeout) |
void set_trace(lprec *lp, unsigned char trace) | void setTrace(boolean trace) |
unsigned char set_upbo(lprec *lp, int column, REAL value) | void setUpbo(int colnr, double value) throws LpSolveException |
unsigned char set_var_branch(lprec *lp, int column, int branch_mode) | void setVarBranch(int colnr, int branchMode) throws LpSolveException |
unsigned char set_var_weights(lprec *lp, REAL *weights) | void setVarWeights(double[] weights) throws LpSolveException |
void set_verbose(lprec *lp, int verbose) | void setVerbose(int verbose) |
int solve(lprec *lp) | int solve() throws LpSolveException |
unsigned char str_add_column (lprec* lp, char* col_string) | void strAddColumn(String column) throws LpSolveException |
unsigned char str_add_constraint (lprec* lp, char *row_string, int constr_type, REAL rh) | void strAddConstraint(String row, int constrType, double rh) throws LpSolveException |
unsigned char str_add_lag_con (lprec* lp, char *row_string, int con_type, REAL rhs) | void strAddLagCon(String row, int constrType, double rh) throws LpSolveException |
unsigned char str_set_obj_fn(lprec *lp, char *row_string) | void strSetObjFn(String row) throws LpSolveException |
unsigned char str_set_rh_vec(lprec *lp, char *rh_string) | void strSetRhVec(String rh) throws LpSolveException |
REAL time_elapsed(lprec *lp) | double timeElapsed() |
void unscale(lprec *lp) | void unscale() |
unsigned char write_freeMPS(lprec *lp, FILE *stream) | <Not implemented, use writeFreeMps instead> |
unsigned char write_freemps(lprec *lp, char *filename) | void writeFreeMps(String filename) throws LpSolveException |
unsigned char write_lp(lprec *lp, char *filename) | void writeLp(String filename) throws LpSolveException |
unsigned char write_LP(lprec *lp, FILE *stream) | <Not implemented, use writeLp instead> |
unsigned char write_mps(lprec *lp, char *filename) | void writeMps(String filename) throws LpSolveException |
unsigned char write_MPS(lprec *lp, FILE *stream) | <Not implemented, use writeMps instead> |
unsigned char write_XLI(lprec *lp, char *filename, char *options, unsigned char results) | void writeXLI(String filename, String options, boolean results) throws LpSolveException |
lp_solve is a free (see LGPL for the GNU lesser general public license) linear (integer) programming solver based on the revised simplex method and the Branch-and-bound method for the integers. lp_solve has its own community via the Yahoo group http://groups.yahoo.com/group/lp_solve. There you can find the latest sources, executables for the common platforms, examples, manuals and a message board where people can share their thoughts on lp_solve.
lp_solve is written in ANSI C and can be compiled on many different platforms like Linux and Windows. Basically, lp_solve is a library, a set of routines, that can be called easily from programming languages like C, C++, C# and VB. Unfortunately, there is no simple and straightforward way to use native C libraries like lp_solve in Java programs. This library (also called "Java wrapper") is designed to remedy this shortcoming. It consists of two main parts:
LpSolve
class.This document should help you getting started using the Java wrapper and lp_solve in your
Java programs. Read it in addition to the documentation that comes with lp_solve.
Always refer to the lp_solve docs as ultimate reference for
using the routines of the optimization library.
Bug reports, succes stories and requests for changes concerning the Java wrapper are welcome
by email at juergen.ebert@web.de
or in the lp_solve discussion group.
The current wrapper version was written to work with lp_solve 5.5.0.9 and was tested under Windows XP and Linux. As long as the API stays the same, other versions of lp_solve are likely to work as well. The wrapper requires a Java Runtime Environment 1.3 or later.
The latest version of the Java wrapper can be found in the files section of the lp_solve group. The wrapper is released under the same LGPL license conditions as lp_solve. A copy of the LGPL text is contained in the distribution archive.
lp_solve_5.5_dev.(zip or tar.gz)
and lp_solve_5.5_exe.(zip or tar.gz)
to a standard library directory for your target platform.
On Windows, a typical place would be \WINDOWS
or \WINDOWS\SYSTEM32
.
On Linux, a typical place would be the directory /usr/local/lib
.
lpsolve55j.dll
to the directory that already contains lpsolve55.dll
.
liblpsolve55j.so
to the directory that already contains liblpsolve55.so
. Run ldconfig
to include
the library in the shared libray cache.
To create a Java application that uses lp_solve routines, you must perform the following steps:
lpsolve55j.jar
from the Java wrapper distribution to a
directory that is included in the CLASSPATH of your java program.lpsolve.*
at the beginning of your
source file.LpSolve.makeLp(...)
or one of the other static factory methods of the LpSolve
class to create a LpSolve
instance. Each LpSolve
instance represents an optimization
problem.LpSolve
instance to define the problem and obtain the solution.
Use the examples and implementation notes later in this documentation for further
information.lpsolve55j.jar
in the CLASSPATH.
Also, on Windows, if you installed the native stub library in a directory that is not included
in the PATH variable, you have to define the Java system variable java.library.path
which must point to the installation directory. On Linux, the equivalent of the Windows PATH
variable is called LD_LIBRARY_PATH.The following program is a very simple example that shows how to program with lp_solve in Java.
import lpsolve.*; public class Demo { public static void main(String[] args) { try { // Create a problem with 4 variables and 0 constraints LpSolve solver = LpSolve.makeLp(0, 4); // add constraints solver.strAddConstraint("3 2 2 1", LpSolve.LE, 4); solver.strAddConstraint("0 4 3 1", LpSolve.GE, 3); // set objective function solver.strSetObjFn("2 3 -2 3"); // solve the problem solver.solve(); // print solution System.out.println("Value of objective function: " + solver.getObjective()); double[] var = solver.getPtrVariables(); for (int i = 0; i < var.length; i++) { System.out.println("Value of var[" + i + "] = " + var[i]); } // delete the problem and free memory solver.deleteLp(); } catch (LpSolveException e) { e.printStackTrace(); } } }
The following code fragment shows you how to use callbacks in Java.
The example defines an anonymous inner class that implements the AbortListener
interface which is then passed to the putAbortfunc
method.
LpSolve solver = LpSolve.makeLp(0, 4); AbortListener abortfunc = new AbortListener() { public boolean abortfunc(LpSolve problem, Object handle) { System.out.println("Java abortfunc called, handle = " + handle); return false; } }; solver.putAbortfunc(abortfunc, new Integer(123));
Follow these steps to run the demo application, which is a port of the C demo program that comes with lp_solve to the Java language. You will need a Java Runtime Environment (JRE) on your machine in order to run the demo. You can download the latest JRE from http://java.sun.com
demo
directory and
start the batch script "run_demo.bat".demo
directory of the wrapper distribution and
run "sh run_demo".In the demo
directory you will find
the file LpSolveTest.java
which contains more than 100
JUnit test cases (see http://www.junit.org for
details about this highly useful software)
to strengthen the faith in the Java wrapper implementation. The test cases
may also seve as examples of basic lp_solve usage in Java. You will need
the library junit.jar
in your CLASSPATH
to run the test cases.
junit.jar
is included in the lib
directory of the Java wrapper. You
can run the test cases directly by starting the batch script "run_unittests.bat" on Windows
or "sh run_unittests" on Linux.
str_add_constraint
becomes strAddConstraint
in Java.lprec*
argument taken by almost all lp_solve API routines is hidden
completely inside the LpSolve
class. All methods that create new lprec
structures were made static methods of the LpSolve
class.set_row_name
returns FALSE if an error has occured. In Java,
setRowName
is of type void and throws a LpSolveException
.boolean
. Example:
set_debug(lprec *lp, unsigned char debug)
is setDebug(boolean debug)
in Java.
LpSolve
object, which represents a problem, is only used by one thread at a
time.get_ptr_sensitivity_rhs
, get_ptr_reduced_costs
,
get_ptr_sensitivity_obj
, and get_ptr_sensitivity_objex
are not implemented,
because it is not possible in Java to pass pointers by reference to a method. Use the corresponding
methods without the Ptr
part in the method name instead, which require allocation
of the resulting arrays by the caller.reference.html
for details on how the lp_solve API functions
are mapped to the Java methods.The Java wrapper archive contains precompiled binary libraries for Windows and Linux. If you just want to use the wrapper there should be no need to build the libs from the sources. But if you absolutely have to, follow the guidelines in this chapter.
lp_solve_5.5_dev.zip
unpackedlib
directory and edit the file build.bat
.
Change the path to the directory where you unpacked the lp_solve Windows
archive. Run the script to build lpsolve55j.dll
.
The dll will be created in directory win32 or win64 depending on the OS.
lp_solve_5.5_dev.tar.gz
unpackedlib
directory and edit the file build
.
Change the paths to the directory where you unpacked the lp_solve linux archive
and where the JDK is installed.
Run sh build
to build liblpsolve55j.so
.
The dll will be created in directory ux32 or ux64 depending on the OS.
Change to the lib/mac
directory and edit the file build_osx
.
Change the directory paths as indicated in the comments.
Thanks to Sean P. Kane (spkane@genomatica.com) who provided this build script.
Jython (http://www.jython.org) is a 100% Java implementation of the popular scripting language Python. One of the most remarkable features of Jython is the seamless interaction between Python and Java. Java programmers can add the Jython libraries to their system to allow end users to write scripts that add functionality to the application. On the other hand, Python/Jython programs can interact with Java packages or with running Java applications.
lp_solve functions can be called via the Java wrapper from Python/Jython programs.
See the file demo.py
in the demo
directory of the Java wrapper distribution
for an example program.
To run this program, you must install lp_solve, the Java wrapper, and Jython. Don't forget
to include lpsolve55j.jar
in the Java CLASSPATH when you run Jython.
ZimplZimpl is a language to translate the mathematical model of a problem into a linear or (mixed-) integer mathematical program expressed in .lp or .mps file format which can be read and (hopefully) solved by a LP or MIP solver. See http://www.zib.de/koch/zimpl/ for the home page of this tool and examples. On the above page, a command line tool is provided to read a model written in the Zimpl language and it creates a CPLEX lp file.
lp_solve is able to read this generated CPLEX lp file via the xli_CPLEX XLI driver, but that would require an extra step. lp_solve -rxli xli_Zimpl chvatal_diet.zpl This gives as result: Value of objective function: 97 Actual values of the variables: x$Oatmeal 4 x$Chicken 0 x$Eggs 0 x$Milk 5 x$Pie 2 x$Pork 0 OptionsThe XLI accepts several options: -b Enable Bison (Lex parser) debugging output. -D name=value Sets the parameter name to the specified value. This is equivalent with having this line in the ZIMPL program: param name:=val. -f enable flex debugging output. -n cm|cn|cf name column make/name/full -O Try to reduce the generated LP by doing some presolve analysis. -s seed Positive seed number for the random number generator. -v[0-5] Set the verbosity level. 0 is quiet, 1 is default, 2 is verbose, 3 and 4 are chatter, and 5 is debug. -V show version info These options are the same as the stand-alone zimpl program. The lp_solve command line program can provide these parameters via the -rxliopt argument. lp_solve -rxli xli_Zimpl chvatal_diet.zpl -rxliopt "-v0 -O" Generating ZIMPL modelsThe XLI can also create a ZIMPL model, however it doesn't use the strength of the language. Constraints are written out line per line. But it can be a starter. For example: lp_solve model.lp -wxli xli_Zimpl model.zpl This gives as model.zpl: # Variable definitions var x >= 0; var y >= 0; # Objective function maximize obj: +143*x +60*y; # Constraints subto R1: +120*x +210*y <= 15000; subto R2: +110*x +30*y <= 4000; subto R3: +x +y <= 75; APIUse the lpsolve API call read_XLI to read a model and write_XLI to write a model. See also External Language Interfaces. IDEAlso from within the IDE, this XLI can be used. However, some entries must be added in LpSolveIDE.ini (in the folder where the IDE is installed). In the [XLI] section the following must be added: lib5=xli_ZIMPL And a new section for the ZIMPL XLI must also be added: [xli_ZIMPL] extension=.zpl language=ZIMPL Then make sure that the xli_ZIMPL.dll is available for the IDE. This must be done by placing this dll in the IDE folder or in the Windows system32 folder. Example modelschvatal_diet.zpl# $Id: chvatal_diet.zpl,v 1.2 2003/10/02 08:20:12 bzfkocht Exp $ # # From V. Chvatal: Linear Programming # Chapter 1, Page 3ff. # # A diet problem # set Food := { "Oatmeal", "Chicken", "Eggs", "Milk", "Pie", "Pork" }; set Nutrients := { "Energy", "Protein", "Calcium" }; set Attr := Nutrients + {"Servings", "Price"}; param needed[Nutrients] := <"Energy"> 2000, <"Protein"> 55, <"Calcium"> 800; param data[Food * Attr] := | "Servings", "Energy", "Protein", "Calcium", "Price" | |"Oatmeal" | 4 , 110 , 4 , 2 , 3 | |"Chicken" | 3 , 205 , 32 , 12 , 24 | |"Eggs" | 2 , 160 , 13 , 54 , 13 | |"Milk" | 8 , 160 , 8 , 284 , 9 | |"Pie" | 2 , 420 , 4 , 22 , 20 | |"Pork" | 2 , 260 , 14 , 80 , 19 |; # (kcal) (g) (mg) (cents) var x[<f> in Food] integer >= 0 <= data[f, "Servings"]; minimize cost: sum <f> in Food : data[f, "Price"] * x[f]; subto need : forall <n> in Nutrients do sum <f> in Food : data[f, n] * x[f] >= needed[n]; model.lp/* model.lp */ max: 143 x + 60 y; 120 x + 210 y <= 15000; 110 x + 30 y <= 4000; x + y <= 75; |
get_solutionlimitReturns the solution number that must be returned. int get_solutionlimit(lprec *lp); Return Value get_solutionlimit returns the solution number that must be returned. This value gives the number of the solution that must be returned. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI Remarks This is only valid if there are integer, semi-continious or SOS variables in the model so that the branch-and-bound algoritm is used. If there are more solutions with the same objective value, then this number specifies which solution must be returned. This can be used to retrieve all possible solutions. Start with 1 till get_solutioncount Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_solutionlimit, get_solutioncount |
set_mip_gapSpecifies the MIP gap value. void set_mip_gap(lprec *lp, unsigned char absolute, REAL mip_gap); Return Value set_mip_gap has no return value. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI absolute If TRUE then the absolute MIP gap is set, else the relative MIP gap mip_gap The MIP gap. Remarks The set_mip_gap function sets the MIP gap that specifies a tolerance for
the branch and bound algorithm. This tolerance is the difference between the
best-found solution yet and the current solution. If the difference is smaller
than this tolerance then the solution (and all the sub-solutions) is rejected.
This can result in faster solving times, but results in a solution which is not
the perfect solution. So be careful with this tolerance. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, get_mip_gap, get_epsd, set_epsd, set_infinite, get_infinite, is_infinite, set_epsint, get_epsint, set_epsb, get_epsb, set_epsel, get_epsel, get_epspivot, set_epspivot, set_epsperturb, get_epsperturb |
is_integerscalingReturns if integer scaling is active. unsigned char is_integerscaling(lprec *lp); Return Value is_integerscaling returns if integer scaling is active (SCALE_INTEGERS set in get_scalelimit) Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI Remarks The is_integerscaling function returns if integer scaling is active (SCALE_INTEGERS set in get_scalelimit). By default integers are not scaled. set_scaling must be called to active this feature. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, get_scaling, set_scaling, set_scalelimit, get_scalelimit |
set_epsdSpecifies the value that is used as a tolerance for reduced costs to determine whether a value should be considered as 0. void set_epsd(lprec *lp, REAL epsd); Return Value set_epsd has no return value. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI epsd The value that is used as a tolerance for reduced costs to determine whether a value should be considered as 0. Remarks The set_epsd function specifies the value that is used as a tolerance for reduced costs to
determine whether a value should be considered as 0. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, get_epsd, set_infinite, is_infinite, get_infinite, set_epsint, get_epsint, set_epsb, get_epsb, set_epsel, get_epsel, get_epspivot, set_epspivot, set_epsperturb, get_epsperturb, set_mip_gap, get_mip_gap |
reset_paramsResets parameters back to their default values. void reset_params(lprec *lp); Return Value No return value. Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI Remarks This routine resets parameters back to their default values. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, read_params, write_params |
O-Matrix is an integrated environment for analysing and visualizing data, and building turnkey scientific and engineering computing solutions. The program includes hundreds of engineering and statistical functions for solving a broad range of technical computing problems. Easy-to-use and flexible plotting commands enable you to rapidly build design prototypes, and implement sophisticated systems.
The foundation of O-Matrix is a high-performance matrix language that is specifically designed for high-performance technical computing. The notation of this language will dramatically reduce your design and implementation efforts, and enable the construction of systems that execute far quicker than other interpreted environments. O-Matrix also provides a compatibility mode that enables you to run MATLAB m-files. This enables you to leverage existing m-files, and simplifies the transition to O-Matrix for users experienced with MATLAB.
The O-Matrix environment is interpreted which means your commands are immediately executed as you enter them. Textual output is displayed in the Command window, and plotting commands are displayed in one or more Graphic windows. The environment provides a debugger for debugging, analysing, and profiling complex algorithms.
We will not discuss the specifics of O-Matrix here but instead refer the reader to the O-Matrix website.
lpsolve is callable from O-Matrix via a dynamic linked DLL function. As such, it looks like lpsolve is fully integrated with O-Matrix. Matrices can directly be transferred between O-Matrix and lpsolve in both directions. The complete interface is written in C so it has maximum performance. The whole lpsolve API is implemented with some extra's specific for O-Matrix (especially for matrix support). So you have full control to the complete lpsolve functionality via the omlpsolve O-Matrix driver. If you find that this involves too much work to solve an lp model then you can also work via higher-level script files that can make things a lot easier. See further in this article.
Compile and build omlpsolve: ---------------------------- 1. Under Windows, the Microsoft Visual C/C++ compiler must be installed and the environment variables must be active do that when a command prompt is opened, the cl and nmake commands can be executed. 2. Go to directory lp_solve_5.5\extra\O-Matrix\lpsolve 3. To compile and build omlpsolve, enter the following command: cvc Load the omlpsolve driver in the O-Matrix memory space: ------------------------------------------------------- 1. Under Windows, make sure that the lpsolve55.dll file is somewhere in the path (archive lp_solve_5.5.0.15_dev.zip) 2. A precompiled library is provided for Windows (omlpsolve.dll). 3. Start O-Matrix 4. Enter the following command in O-Matrix: O> dll <path>\omlpsolve.dll, omlpsolve This can also be added in autoexec.oms to automatically load the omlpsolve driver.
Note that O-Matrix version 5.8 or above is strongly recommended. Lower versions (at least 5.7) should work with this driver, but these versions don't have the ability to print information on the command prompt. For example default while a solve is done, information is printed to the command window. This will only be visible from version 5.8 or above.
O-Matrix is ideally suited to handle linear programming problems. These are problems in which you have a quantity, depending linearly on several variables, that you want to maximize or minimize subject to several constraints that are expressed as linear inequalities in the same variables.If the number of variables and the number of constraints are small, then there are numerous mathematical techniques for solving a linear programming problem. Indeed these techniques are often taught in high school or university level courses in finite mathematics.But sometimes these numbers are high, or even if low, the constants in the linear inequalities or the object expression for the quantity to be optimized may be numerically complicated in which case a software package like O-Matrix is required to effect a solution.
To make this possible, a driver program is needed: omlpsolve (omlpsolve.dll under Windows). This driver must be loaded in O-Matrix and O-Matrix can call the omlpsolve solver.
This driver calls lpsolve via the lpsolve shared library (lpsolve55.dll under Windows). This has the advantage that the omlpsolve driver doesn't have to be recompiled when an update of lpsolve is provided. The shared library must be somewhere in the Windows path.
So note the difference between the O-Matrix lpsolve driver that is called omlpsolve and the lpsolve library that implements the API that is called lpsolve55.
There are also some O-Matrix script files (.oms) as a quick start.
The first thing that must be done, each time O-Matrix is restarted and you want to use lpsolve is load the omlpsolve driver into the O-Matrix workspace. This is done via the dll command. Suppose that omlpsolve.dll is installed in c:\omwin\dll, then the following command must be used to load the driver:
dll c:\omwin\dll\omlpsolve.dll, omlpsolve
That is basically all you need to do. From now on, you can use the library. This until a clear command is given or O-Matrix is restarted. Then this command must be given again to reload the library.
To make things easier, you can edit the file autoexec.oms with your favourite editor (or notepad) in the omwin folder and add above line at the end of this file (before the last end). That will automatically load the lpsolve driver in memory when O-Matrix is started and also when a clear command is executed. So it will appear as if the omlpsolve command is then always available.
To test if everything is installed correctly, enter omlpsolve in the O-Matrix command prompt. If it gives the following, then everything is ok:
omlpsolve O-Matrix Interface version 5.5.0.6 using lpsolve version 5.5.0.15 Usage: [ret1, ret2, ...] = omlpsolve("functionname", arg1, arg2, ...)
Possibly, this is followed with:
No printing capability to command window available. You need to upgrade to version 5.8 for this feature.
Then you are working with an O-Matrix version lower than 5.8. The driver should work, but nothing is printed on the command window when lpsolve has something to report (for example while solving).
However, if you get a message box with the following:
The identifier omlpsolve is not defined.
Then either the dll command that was previous given was unsuccessful (or not given at all) or something was misspelled after the ,
If you get the following:
This application has failed to start because lpsolve55.dll was not found. Re-installing the application may fix this problem.
Then O-Matrix can find the omlpsolve driver program, but the driver program cannot find the lpsolve library that contains the lpsolve implementation. This library is called lpsolve55.dll and should be on your system in a directory that in the PATH environment variable. This path can be shown via the command getenv("PATH")
The lpsolve55.dll files must be in one of these specified directories. It is common to place this in the WINDOWS\system32 folder.
All this is developed and tested with O-Matrix version 5.7. This is the minimum supported release. Older releases are unsupported.
In the following text, O> before the O-Matrix commands is the O-Matrix command line. Only the text after O> must be entered.
To call an lpsolve function, the following syntax must be used:
O> [ret1, ret2, ...] = omlpsolve("functionname", arg1, arg2, ...)
The return values are optional and depend on the function called. functionname must always be enclosed between double quotes to make it alphanumerical and it is case sensitive. The number and type of arguments depend on the function called. Some functions even have a variable number of arguments and a different behaviour occurs depending on the type of the argument. functionname can be (almost) any of the lpsolve API routines (see lp_solve API reference) plus some extra O-Matrix specific functions. Most of the lpsolve API routines use or return an lprec structure. To make things more robust in O-Matrix, this structure is replaced by a handle or the model name. The lprec structures are maintained internally by the lpsolve driver. The handle is an incrementing number starting from 0. Starting from driver version 5.5.0.2, it is also possible to use the model name instead of the handle. This can of course only be done if a name is given to the model. This is done via lpsolve routine set_lp_name or by specifying the model name in routine read_lp. See Using model name instead of handle.
Almost all callable functions can be found in the lp_solve API reference. Some are exactly as described in the reference guide, others have a slightly different syntax to make maximum use of the O-Matrix functionality. For example make_lp is used identical as described. But get_variables is slightly different. In the API reference, this function has two arguments. The first the lp handle and the second the resulting variables and this array must already be dimensioned. When lpsolve is used from O-Matrix, nothing must be dimensioned in advance. The omlpsolve driver takes care of dimensioning all return variables and they are always returned as return value of the call to omlpsolve. Never as argument to the routine. This can be a single value as for get_objective (although O-Matrix stores this in a 1x1 matrix) or a matrix or vector as in get_variables. In this case, get_variables returns a 4x1 matrix (vector) with the result of the 4 variables of the lp model.
(Note that you can execute this example by entering command per command as shown below or by just entering example1. This will execute example1.oms.)
O> lp=omlpsolve("make_lp", 0, 4); O> omlpsolve("set_verbose", lp, 3); O> omlpsolve("set_obj_fn", lp, [1, 3, 6.24, 0.1]); O> omlpsolve("add_constraint", lp, [0, 78.26, 0, 2.9], 2, 92.3); O> omlpsolve("add_constraint", lp, [0.24, 0, 11.31, 0], 1, 14.8); O> omlpsolve("add_constraint", lp, [12.68, 0, 0.08, 0.9], 2, 4); O> omlpsolve("set_lowbo", lp, 1, 28.6); O> omlpsolve("set_lowbo", lp, 4, 18); O> omlpsolve("set_upbo", lp, 4, 48.98); O> omlpsolve("set_col_name", lp, 1, "COLONE"); O> omlpsolve("set_col_name", lp, 2, "COLTWO"); O> omlpsolve("set_col_name", lp, 3, "COLTHREE"); O> omlpsolve("set_col_name", lp, 4, "COLFOUR"); O> omlpsolve("set_row_name", lp, 1, "THISROW"); O> omlpsolve("set_row_name", lp, 2, "THATROW"); O> omlpsolve("set_row_name", lp, 3, "LASTROW"); O> omlpsolve("write_lp", lp, "a.lp"); O> omlpsolve("get_mat", lp, 1, 2) 78.2600 O> omlpsolve("solve", lp) 0 O> omlpsolve("get_objective", lp) 31.7828 O> omlpsolve("get_variables", lp) { 28.6 0 0 31.8276 } O> omlpsolve("get_constraints", lp) { 92.3 6.8640 391.293 }
Note that there are some commands that return an answer. To see the answer, the command was not terminated with a semicolon (;). If the semicolon is put at the end of a command, the answer is not shown. However it is also possible to write the answer in a variable. In that case the result is never shown. With or without a terminating semicolon. For example:
O> obj=omlpsolve("get_objective", lp)
Or:
O> obj=omlpsolve("get_objective", lp);
Both will only write the result in variable obj without showing anything on screen. get_variables and get_constraints return a vector with the result. This can also be put in a variable:
O> x=omlpsolve("get_variables", lp); O> b=omlpsolve("get_constraints", lp);
It is always possible to show the contents of a variable by just giving it as command:
O> x { 28.6 0 0 31.8276 }
Don't forget to free the handle and its associated memory when you are done:
O> omlpsolve("delete_lp", lp);
O> lp=omlpsolve("make_lp", 0, 4); O> omlpsolve("set_lp_name", lp, "mymodel"); O> omlpsolve("set_verbose", "mymodel", 3); O> omlpsolve("set_obj_fn", "mymodel", [1, 3, 6.24, 0.1]); O> omlpsolve("add_constraint", "mymodel", [0, 78.26, 0, 2.9], 2, 92.3); O> omlpsolve("add_constraint", "mymodel", [0.24, 0, 11.31, 0], 1, 14.8); O> omlpsolve("add_constraint", "mymodel", [12.68, 0, 0.08, 0.9], 2, 4); O> omlpsolve("set_lowbo", "mymodel", 1, 28.6); O> omlpsolve("set_lowbo", "mymodel", 4, 18); O> omlpsolve("set_upbo", "mymodel", 4, 48.98); O> omlpsolve("set_col_name", "mymodel", 1, "COLONE"); O> omlpsolve("set_col_name", "mymodel", 2, "COLTWO"); O> omlpsolve("set_col_name", "mymodel", 3, "COLTHREE"); O> omlpsolve("set_col_name", "mymodel", 4, "COLFOUR"); O> omlpsolve("set_row_name", "mymodel", 1, "THISROW"); O> omlpsolve("set_row_name", "mymodel", 2, "THATROW"); O> omlpsolve("set_row_name", "mymodel", 3, "LASTROW"); O> omlpsolve("write_lp", "mymodel", "a.lp"); O> omlpsolve("get_mat", "mymodel", 1, 2) 78.2600 O> omlpsolve("solve", "mymodel") 0 O> omlpsolve("get_objective", "mymodel") 31.7828 O> omlpsolve("get_variables", "mymodel") { 28.6 0 0 31.8276 } O> omlpsolve("get_constraints", "mymodel") { 92.3 6.8640 391.293 }
So everywhere a handle is needed, you can also use the model name. You can even mix the two methods.
There is also a specific O-Matrix routine to get the handle from the model name: get_handle.
For example:
O> omlpsolve("get_handle", "mymodel") 0
Don't forget to free the handle and its associated memory when you are done:
O> omlpsolve("delete_lp", "mymodel")
In the next part of this documentation, the handle is used. But if you name the model, the name could thus also be used.
O> omlpsolve("add_constraint", lp, [0.24, 0, 11.31, 0], 1, 14.8);
Most of the time, variables are used to provide the data:
O> omlpsolve("add_constraint", lp, a1, 1, 14.8);
Where a1 is a matrix variable.
Matrices with too few or too much elements gives an 'invalid vector.' error.
Most of the time, omlpsolve needs vectors (rows or columns). In all situations, it doesn't matter if the vectors are row or column vectors. The driver accepts them both. For example:
O> omlpsolve("add_constraint", lp, {0.24, 0, 11.31, 0}, 1, 14.8);
Which is a column vector, but it is also accepted.
An important final note. Several lp_solve API routines accept a vector where the first element (element 0) is not used. Other lp_solve API calls do use the first element. In the O-Matrix interface, there is never an unused element in the matrices. So if the lp_solve API specifies that the first element is not used, then this element is not in the O-Matrix matrix.
Because O-Matrix is all about matrices, all lpsolve API routines that need a column or row number to get/set information for that
column/row are extended in the omlpsolve O-Matrix driver to also work with matrices. For example set_int in the API can
only set the integer status for one column. If the status for several integer variables must be set, then set_int
must be called multiple times. The omlpsolve O-Matrix driver however also allows specifying a vector to set the integer
status of all variables at once. The API call is: return = omlpsolve("set_int", lp, column, must_be_int). The
matrix version of this call is: return = omlpsolve("set_int", lp, [must_be_int]).
The API call to return the integer status of a variable is: return = omlpsolve("is_int", lp, column). The
matrix version of this call is: [is_int] = omlpsolve("is_int", lp)
Also note the get_mat and set_mat routines. In O-Matrix these are extended to return/set the complete constraint matrix.
See following example.
Above example can thus also be done as follows:
(Note that you can execute this example by entering command per command as shown below or by just entering example2.
This will execute example2.oms.)
O> lp=omlpsolve("make_lp", 0, 4); O> omlpsolve("set_verbose", lp, 3); O> omlpsolve("set_obj_fn", lp, [1, 3, 6.24, 0.1]); O> omlpsolve("add_constraint", lp, [0, 78.26, 0, 2.9], 2, 92.3); O> omlpsolve("add_constraint", lp, [0.24, 0, 11.31, 0], 1, 14.8); O> omlpsolve("add_constraint", lp, [12.68, 0, 0.08, 0.9], 2, 4); O> omlpsolve("set_lowbo", lp, [28.6, 0, 0, 18]); O> omlpsolve("set_upbo", lp, [INF, INF, INF, 48.98]); O> omlpsolve("set_col_name", lp, {"COLONE", "COLTWO", "COLTHREE", "COLFOUR"}); O> omlpsolve("set_row_name", lp, {"THISROW", "THATROW", "LASTROW"}); O> omlpsolve("write_lp", lp, "a.lp"); O> omlpsolve("get_mat", lp) { [ 0 , 78.26 , 0 , 2.9 ] [ 0.24 , 0 , 11.31 , 0 ] [ 12.68 , 0 , 0.08 , 0.9 ] } O> omlpsolve("solve", lp) 0 O> omlpsolve("get_objective", lp) 31.7828 O> omlpsolve("get_variables", lp) { 28.6 0 0 31.8276 } O> omlpsolve("get_constraints", lp) { 92.3 6.8640 391.293 }
Note the usage of INF in set_upbo. This stands for "infinity". Meaning an infinite upper bound. It is also possible to use -INF to express minus infinity. This can for example be used to create a free variable.
To show the full power of the matrices, let's now do some matrix calculations to check the solution. It works further on above example:
O> A=omlpsolve("get_mat", lp); O> X=omlpsolve("get_variables", lp); O> B = A * X O> B { 92.3 6.864 391.293 }
So what we have done here is calculate the values of the constraints (RHS) by multiplying the constraint matrix with the solution vector. Now take a look at the values of the constraints that lpsolve has found:
O> omlpsolve("get_constraints", lp) { 92.3 6.864 391.293 }
Exactly the same as the calculated B vector, as expected.
Also the value of the objective can be calculated in a same way:
O> C=omlpsolve("get_obj_fn", lp); O> X=omlpsolve("get_variables", lp); O> obj = C * X O> obj 31.7828
So what we have done here is calculate the value of the objective by multiplying the objective vector with the solution vector. Now take a look at the value of the objective that lpsolve has found:
O> omlpsolve("get_objective", lp) 31.7828
Again exactly the same as the calculated obj value, as expected.
O> lp=omlpsolve("make_lp", 0, 4); O> omlpsolve("set_verbose", lp, 3); O> omlpsolve("add_constraint", lp, [0, 78.26, 0, 2.9], 2, 92.3); O> omlpsolve("add_constraint", lp, [0.24, 0, 11.31, 0], 1, 14.8); O> omlpsolve("add_constraint", lp, [12.68, 0, 0.08, 0.9], 2, 4);
Note the 3rd parameter on set_verbose and the 4th on add_constraint. These are lp_solve constants. One could define all the possible constants in O-Matrix and then use them in the calls, but that has several disadvantages. First there stays the possibility to provide a constant that is not intended for that particular call. Another issue is that calls that return a constant are still returning it numerical.
Both issues can now be handled by string constants. The above code can be done as following with string constants:
O> lp=omlpsolve("make_lp", 0, 4); O> omlpsolve("set_verbose", lp, "IMPORTANT"); O> omlpsolve("add_constraint", lp, [0, 78.26, 0, 2.9], "GE", 92.3); O> omlpsolve("add_constraint", lp, [0.24, 0, 11.31, 0], "LE", 14.8); O> omlpsolve("add_constraint", lp, [12.68, 0, 0.08, 0.9], "GE", 4);
This is not only more readable, there is much lesser chance that mistakes are being made. The calling routine knows which constants are possible and only allows these. So unknown constants or constants that are intended for other calls are not accepted. For example:
O> omlpsolve("set_verbose", lp, "blabla"); BLABLA: Unknown. O> omlpsolve("set_verbose", lp, "GE"); GE: Not allowed here.
Note the difference between the two error messages. The first says that the constant is not known, the second that the constant cannot be used at that place.
Constants are case insensitive. Internally they are always translated to upper case. Also when returned they will always be in upper case.
The constant names are the ones as specified in the documentation of each API routine. There are only 3 exceptions, extensions actually. "LE", "GE" and "EQ" in add_constraint and is_constr_type can also be "<", "<=", ">", ">=", "=". When returned however, "GE", "LE", "EQ" will be used.
Also in the matrix version of calls, string constants are possible. For example:
O> omlpsolve("set_constr_type", lp, {"LE", "EQ", "GE"});
Some constants can be a combination of multiple constants. For example set_scaling:
O> omlpsolve("set_scaling", lp, 3+128);
With the string version of constants this can be done as following:
O> omlpsolve("set_scaling", lp, "SCALE_MEAN|SCALE_INTEGERS");
| is the OR operator used to combine multiple constants. There may optinally be spaces before and after the |.
Not all OR combinations are legal. For example in set_scaling, a choice must be made between SCALE_EXTREME, SCALE_RANGE, SCALE_MEAN, SCALE_GEOMETRIC or SCALE_CURTISREID. They may not be combined with each other. This is also tested:
O> omlpsolve("set_scaling", lp, "SCALE_MEAN|SCALE_RANGE"); SCALE_RANGE cannot be combined with SCALE_MEAN
Everywhere constants must be provided, numeric or string values may be provided. The routine automatically interpretes them.
Returning constants is a different story. The user must let lp_solve know how to return it. Numerical or as string. The default is numerical:
O> omlpsolve("get_scaling", lp) 131
To let lp_solve return a constant as string, a call to a new function must be made: return_constants
O> omlpsolve("return_constants", 1);
From now on, all returned constants are returned as string:
O> omlpsolve("get_scaling", lp) SCALE_MEAN|SCALE_INTEGERS
Also when an array of constants is returned, they are returned as string when return_constants is set:
O> omlpsolve("get_constr_type", lp) LE EQ GE
This for all routines until return_constants is again called with 0:
O> omlpsolve("return_constants", 0);
The (new) current setting of return_constants is always returned by the call. Even when set:
O> omlpsolve("return_constants", 1) 1
To get the value without setting it, don"t provide the second argument:
O> omlpsolve("return_constants") 1
In the next part of this documentation, return_constants is the default, 0, so all constants are returned numerical and provided constants are also numerical. This to keep the documentation as compatible as possible with older versions. But don"t let you hold that back to use string constants in your code.
O-Matrix can execute a sequence of statements stored in files. Such files are called oms files because they must have the file type of ".oms" as the last part of their filename (extension).
oms scripts can be compared with batch files or scripts. You can put O-Matrix commands in them and execute them at any time. The oms script is executed like any other command, by entering its name (without the .oms extension).
The omlpsolve O-Matrix distribution contains some example oms scripts to demonstrate this.
You can also edit these files with your favourite text editor (or notepad).
Contains the commands as shown in the first example of this article. To execute and also see which commands are executed in the debug window, use following commands:
O> stop O> trace on example1.oms O> quit O> example1
Note however that execution is much slower when trace is on. It is only used here to see the statements executed.
Contains the commands as shown in the second example of this article. To execute and also see which commands are executed in the debug window, use following commands:
O> stop O> trace on example2.oms O> quit O> example2
Note however that execution is much slower when trace is on. It is only used here to see the statements executed.
Contains the commands of a practical example. See further in this article.
Contains the commands of a practical example. See further in this article.
Contains the commands of a practical example. See further in this article.
Contains the commands of a practical example. See further in this article.
This script uses the API to create a higher-level function called lp_solve. This function accepts as arguments some matrices and options to create and solve an lp model. See the beginning of the file to see its usage:
LP_SOLVE Solves mixed integer linear programming problems. SYNOPSIS: [obj,x,duals] = lp_solve(f,a,b,e,vlb,vub,xint,scalemode,keep) solves the MILP problem max v = f'*x a*x <> b vlb <= x <= vub x(int) are integer ARGUMENTS: The first four arguments are required: f: n vector of coefficients for a linear objective function. a: m by n matrix representing linear constraints. b: m vector of right sides for the inequality constraints. e: m vector that determines the sense of the inequalities: e(i) = -1 ==> Less Than e(i) = 0 ==> Equals e(i) = 1 ==> Greater Than vlb: n vector of lower bounds. If empty or omitted, then the lower bounds are set to zero. vub: n vector of upper bounds. May be omitted or empty. xint: vector of integer variables. May be omitted or empty. scalemode: scale flag. Off when 0 or omitted. keep: Flag for keeping the lp problem after it's been solved. If omitted, the lp will be deleted when solved. OUTPUT: A nonempty output is returned if a solution is found: obj: Optimal value of the objective function. x: Optimal value of the decision variables. duals: solution of the dual problem.
Example of usage. To create and solve following lp-model:
max: -x1 + 2 x2; C1: 2x1 + x2 < 5; -4 x1 + 4 x2 <5; int x2,x1;
The following command can be used:
O> include lp_solve.oms O> [obj, x]=lp_solve([-1, 2], {[2, 1], [-4, 4]}, [5, 5], [-1, -1], [], [], [1, 2]) O> obj 3 O> x { 1 2 }
This script is analog to the lp_solve script and also uses the API to create a higher-level function called lp_maker. This function accepts as arguments some matrices and options to create an lp model. Note that this scripts only creates a model and returns a handle. See the beginning of the file to see its usage:
LP_MAKER Makes mixed integer linear programming problems. SYNOPSIS: lp_handle = lp_maker(f,a,b,e,vlb,vub,xint,scalemode,setminim) make the MILP problem max v = f'*x a*x <> b vlb <= x <= vub x(int) are integer ARGUMENTS: The first four arguments are required: f: n vector of coefficients for a linear objective function. a: m by n matrix representing linear constraints. b: m vector of right sides for the inequality constraints. e: m vector that determines the sense of the inequalities: e(i) < 0 ==> Less Than e(i) = 0 ==> Equals e(i) > 0 ==> Greater Than vlb: n vector of non-negative lower bounds. If empty or omitted, then the lower bounds are set to zero. vub: n vector of upper bounds. May be omitted or empty. xint: vector of integer variables. May be omitted or empty. scalemode: scale flag. Off when 0 or omitted. setminim: Set maximum lp when this flag equals 0 or omitted. OUTPUT: lp_handle is an integer handle to the lp created.
Example of usage. To create following lp-model:
max: -x1 + 2 x2; C1: 2x1 + x2 < 5; -4 x1 + 4 x2 <5; int x2,x1;
The following command can be used:
O> include lp_maker.oms O> lp=lp_maker([-1, 2], {[2, 1], [-4, 4]}, [5, 5], [-1, -1], [], [], [1, 2]) O> lp 0
To solve the model and get the solution:
O> omlpsolve("solve", lp) 0 O> omlpsolve("get_objective", lp) 3 O> omlpsolve("get_variables", lp) { 1 2 }
Don't forget to free the handle and its associated memory when you are done:
O> omlpsolve("delete_lp", lp);
Contains several examples to build and solve lp models. To execute and also see which commands are executed in the debug window, use following commands:
O> stop O> trace on lpdemo.oms O> quit O> lpdemo
Note however that execution is much slower when trace is on. It is only used here to see the statements executed.
Contains several examples to build and solve lp models. Also solves the lp_examples from the lp_solve distribution. To execute and also see which commands are executed in the debug window, use following commands:
O> stop O> trace on ex.oms O> quit O> ex
Note however that execution is much slower when trace is on. It is only used here to see the statements executed.
We shall illustrate the method of linear programming by means of a simple example, giving a combination graphical/numerical solution, and then solve both a slightly as well as a substantially more complicated problem.
Suppose a farmer has 75 acres on which to plant two crops: wheat and barley. To produce these crops, it costs the farmer (for seed, fertilizer, etc.) $120 per acre for the wheat and $210 per acre for the barley.The farmer has $15000 available for expenses. But after the harvest, the farmer must store the crops while awaiting favourable market conditions. The farmer has storage space for 4000 bushels.Each acre yields an average of 110 bushels of wheat or 30 bushels of barley. If the net profit per bushel of wheat (after all expenses have been subtracted) is $1.30 and for barley is $2.00, how should the farmer plant the 75 acres to maximize profit?
We begin by formulating the problem mathematically. First we express the objective, that is the profit, and the constraints algebraically, then we graph them, and lastly we arrive at the solution by graphical inspection and a minor arithmetic calculation.
Let x denote the number of acres allotted to wheat and y the number of acres allotted to barley. Then the expression to be maximized, that is the profit, is clearly
P = (110)(1.30)x + (30)(2.00)y = 143x + 60y.
There are three constraint inequalities, specified by the limits on expenses, storage and acreage. They are respectively:
120x + 210y <= 15000
110x + 30y <= 4000
x + y <= 75
Strictly speaking there are two more constraint inequalities forced by the fact that the farmer cannot plant a negative number of acres, namely:
x >= 0,y >= 0.
Next we graph the regions specified by the constraints. The last two say that we only need to consider the first quadrant in the x-y plane. Here's a graph delineating the triangular region in the first quadrant determined by the first inequality.
O> clear O> X = 0.1:0.05:125; O> Y1 = (15000. - 120*X)/210; O> bar(X, Y1)
Now let's put in the other two constraint inequalities.
O> clear O> X = 0.1:0.05:38; O> mlmode O> Y1 = (15000. - 120*X)/210; O> Y2 = max((4000 - 110.*X)./30, 0); O> Y3 = max(75 - X, 0.); O> Ytop = min(min(Y1, Y2), Y3); O> omatrix O> bar(X, Ytop) O> gtitle("Solution space")
The black area is the solution space that holds valid solutions. This means that any point in this area fulfils the constraints.
Now let's superimpose on top of this picture a contour plot of the objective function P.
O> mlmode meshgrid.m O> [U, V] = meshgrid(0:1:40, 0:1:80); O> Ur = U.row(1) O> Vc = V.col(1) O> Z = 143.*U + 60.*V O> levels = (0:1:11)*1000. O> contour(Z', levels, Ur', Vc'); O> gtitle("Solution space and objective")
The lines give a picture of the objective function. All solutions that intersect with the black area are valid solutions, meaning that this result also fulfils the set constraints. The more the lines go to the right, the higher the objective value is. The optimal solution or best objective is a line that is still in the black area, but with an as large as possible value.
It seems apparent that the maximum value of P will occur on the level curve (that is, level
line) that passes through the vertex of the polygon that lies near (22,53).
It is the intersection of x + y = 75 and 110*x + 30*y = 4000
This is a corner point of the diagram. This is not a coincidence. The simplex algorithm, which is used
by lp_solve, starts from a theorem that the optimal solution is such a corner point.
In fact we can compute the result:
O> x = {[1, 1], [110, 30]} \ {75, 4000} O> print "x =", x x = { 21.875 53.125 }
The acreage that results in the maximum profit is 21.875 for wheat and 53.125 for barley. In that case the profit is:
O> P = [143, 60] * x O> print "Profit, P =", P Profit, P = 6315.63
That is, $6315.63.
Note that these command are in script example3.oms
Now, lp_solve comes into the picture to solve this linear programming problem more generally. After that we will use it to solve two more complicated problems involving more variables and constraints.
For this example, we use the higher-level script lp_maker to build the model and then some lp_solve API calls to retrieve the solution. Here is again the usage of lp_maker:
LP_MAKER Makes mixed integer linear programming problems. SYNOPSIS: lp_handle = lp_maker(f,a,b,e,vlb,vub,xint,scalemode,setminim) make the MILP problem max v = f'*x a*x <> b vlb <= x <= vub x(int) are integer ARGUMENTS: The first four arguments are required: f: n vector of coefficients for a linear objective function. a: m by n matrix representing linear constraints. b: m vector of right sides for the inequality constraints. e: m vector that determines the sense of the inequalities: e(i) < 0 ==> Less Than e(i) = 0 ==> Equals e(i) > 0 ==> Greater Than vlb: n vector of non-negative lower bounds. If empty or omitted, then the lower bounds are set to zero. vub: n vector of upper bounds. May be omitted or empty. xint: vector of integer variables. May be omitted or empty. scalemode: scale flag. Off when 0 or omitted. setminim: Set maximum lp when this flag equals 0 or omitted. OUTPUT: lp_handle is an integer handle to the lp created.
Now let's formulate this model with lp_solve:
O> f = [143, 60]; O> A = {[120, 210], [110, 30], [1, 1]}; O> b = {15000, 4000, 75}; O> lp = lp_maker(f, A, b, [-1, -1, -1], [], [], [], 1, 0); O> solvestat = omlpsolve("solve", lp) O> omlpsolve("get_objective", lp) 6315.63 O> omlpsolve("get_variables", lp) { 21.875 53.125 } O> omlpsolve("delete_lp", lp);
Note that these command are in script example4.oms
With the higher-level script lp_maker, we provide all data to lp_solve. lp_solve returns a handle (lp) to the created model. Then the API call 'solve' is used to calculate the optimal solution of the model. The value of the objective function is retrieved via the API call 'get_objective' and the values of the variables are retrieved via the API call 'get_variables'. At last, the model is removed from memory via a call to 'delete_lp'. Don't forget this to free all memory allocated by lp_solve.
The solution is the same answer we obtained before. Note that the non-negativity constraints are accounted implicitly because variables are by default non-negative in lp_solve.
Well, we could have done this problem by hand (as shown in the introduction) because it is very small and it
can be graphically presented.
Now suppose that the farmer is dealing with a third crop, say corn, and that the corresponding data is:
cost per acre $150.75 yield per acre 125 bushels profit per bushel $1.56
With three variables it is already a lot more difficult to show this model graphically. Adding more variables makes it even impossible because we can't imagine anymore how to represent this. We only have a practical understanding of 3 dimentions, but beyound that it is all very theorethical.
If we denote the number of acres allotted to corn by z, then the objective function becomes:
P = (110)(1.30)x + (30)(2.00)y+ (125)(1.56) = 143x + 60y + 195z
And the constraint inequalities are:
120x + 210y + 150.75z <= 15000
110x + 30y + 125z <= 4000
x + y + z <= 75
x >= 0,y >= 0, z >= 0
The problem is solved with lp_solve as follows:
O> f = [143, 60, 195]; O> A = {[120, 210, 150.75], [110, 30, 125], [1, 1, 1]}; O> b = {15000, 4000, 75}; O> lp = lp_maker(f, A, b, [-1, -1, -1], [], [], [], 1, 0); O> solvestat = omlpsolve("solve", lp) O> omlpsolve("get_objective", lp) 6986.84 O> omlpsolve("get_variables", lp) { 0 56.5789 18.4211 } O> omlpsolve("delete_lp", lp);
Note that these command are in script example5.oms
So the farmer should ditch the wheat and plant 56.5789 acres of barley and 18.4211 acres of corn.
There is no practical limit on the number of variables and constraints that O-Matrix can handle. Certainly none that the relatively unsophisticated user will encounter.Indeed, in many true applications of the technique of linear programming, one needs to deal with many variables and constraints.The solution of such a problem by hand is not feasible, and software like O-Matrix is crucial to success.For example, in the farming problem with which we have been working, one could have more crops than two or three. Think agribusiness instead of family farmer.And one could have constraints that arise from other things beside expenses, storage and acreage limitations. For example:
Below is a sequence of commands that solves exactly such a problem. You should be able to recognize the objective expression and the constraints from the data that is entered. But as an aid, you might answer the following questions:
O> f = [110*1.3, 30*2.0, 125*1.56, 75*1.8, 95*.95, 100*2.25, 50*1.35]; O> A = {[120,210,150.75,115,186,140,85],[110,30,125,75,95,100,50],[1,1,1,1,1,1,1], [1,-1,0,0,0,0,0],[0,0,1,0,-2,0,0],[0,0,0,-1,0,-1,1]}; O> b = {55000, 40000, 400, 0, 0, 0}; O> lp = lp_maker(f, A, b, [-1,-1,-1,-1,-1,-1],[10,10,10,10,20,20,20],[100,INF,50,INF,INF,250,INF],[],1,0); O> solvestat = omlpsolve("solve", lp) O> omlpsolve("get_objective", lp) 75398 O> omlpsolve("get_variables", lp) { 10 10 40 45.6522 20 250 20 } O> omlpsolve("delete_lp", lp);
Note that these command are in script example6.oms
Note that we have used in this formulation the vlb and vub arguments of lp_maker. This to set lower and upper bounds on variables. This could have been done via extra constraints, but it is more performant to set bounds on variables. Also note that Inf is used for variables that have no upper limit. This stands for Infinity.
Note that despite the complexity of the problem, lp_solve solves it almost instantaneously. It seems the farmer should bet the farm on crop number 6.We strongly suggest you alter the expense and/or the storage limit in the problem and see what effect that has on the answer.
Suppose we want to solve the following linear program using O-Matrix:
max 4x1 + 2x2 + x3
s. t. 2x1 + x2 <= 1
x1 + 2x3 <= 2
x1 + x2 + x3 = 1
x1 >= 0
x1 <= 1
x2 >= 0
x2 <= 1
x3 >= 0
x3 <= 2
Convert the LP into O-Matrix format we get:
f = [4, 2, 1]
A = {[2, 1, 0], [1, 0, 2], [1, 1, 1]}
b = {1, 2, 1}
Note that constraints on single variables are not put in the constraint matrix. lp_solve can set bounds on individual variables and this is more performant than creating additional constraints. These bounds are:
l = [ 0, 0, 0]
u = [ 1, 1, 2]
Now lets enter this in O-Matrix:
O> f = [4, 2, 1]; O> A = {[2, 1, 0], [1, 0, 2], [1, 1, 1]}; O> b = {1, 2, 1}; O> l = [ 0, 0, 0]; O> u = [ 1, 1, 2];
Now solve the linear program using O-Matrix: Type the commands
O> lp = lp_maker(f, A, b, [-1, -1, -1], l, u, [], 1, 0); O> solvestat = omlpsolve("solve", lp) O> omlpsolve("get_objective", lp) 2.5 O> omlpsolve("get_variables", lp) { 0.5 0 0.5 } O> omlpsolve("delete_lp", lp)
What to do when some of the variables are missing ?
For example, suppose there are no lower bounds on the variables. In this case define l to be the empty set using the O-Matrix command:
O> l = [];
This has the same effect as before, because lp_solve has as default lower bound for variables 0.
But what if you want that variables may also become negative?
Then you can use -INF as lower bounds:
O> l = [-INF, -INF, -INF];
Solve this and you get a different result:
O> lp = lp_maker(f, A, b, [-1, -1, -1], l, u, [], 1, 0); O> solvestat = omlpsolve("solve", lp) O> omlpsolve("get_objective", lp) 2.66667 O> omlpsolve("get_variables", lp) { 0.666667 -0.333333 0.666667 } O> omlpsolve("delete_lp", lp)
Note that everwhere where lp is used as argument that this can be a handle (lp_handle) or the models name.
These routines are not part of the lpsolve API, but are added for backwards compatibility. Most of them exist in the lpsolve API with another name.
Under Windows, the omlpsolve O-Matrix driver is a dll: omlpsolve.dll
This dll is an interface to the lpsolve55.dll lpsolve dll that contains the implementation of lp_solve.
lpsolve55.dll is distributed with the lp_solve package (archive lp_solve_5.5.0.15_dev.zip). The omlpsolve O-Matrix driver dll (omlpsolve.dll) is just
a wrapper between O-Matrix and lp_solve to translate the input/output to/from O-Matrix and the lp_solve library.
The omlpsolve O-Matrix driver is written in C. To compile this code, Microsoft compiler is needed.
Other compilers might also work, but this is untested.
To make the compilation process easier, a batch file can be used: cvc.bat
It may be necessary to edit this file first to change the path where lp_solve and the O-Matrix dll sources are installed.
Change at the beginning lpsolvepath and dllsrcpath. dllsrcpath must point to the folder where dll.h is located.
To make for release, just enter cvc and everything is build.
This compiles three source files: lpsolve.c, omatrix.c and hash.c
Then these are linked with the library lpsolve55.lib to generate the omlpsolve.dll file.
The optional arguments to cvc are used for development. Source files can be provided and then only these are compiled.
For example hash.c should only be compiled once while developing. So specifying
lpsolve.c as first argument will only compile this file and then link everything. This makes the build process a bit faster.
Also the option -DDEMO can be added to add the demo command to test some functionality of lpsolve. This is also only for debugging.
Also the option -DDEBUG can be added. This to print some debug information while executing omlpsolve.
Should only be used for debugging purposes.
Note that the omlpsolve.dll file can be locked by O-Matrix. Then the build process will fail because the dll can not be overwritten. This can be solved by giving the clear command in O-Matrix. This will free the dll.
At this moment, there is no O-Matrix version for this platform.
See also Using lpsolve from MATLAB, Using lpsolve from Sysquake, Using lpsolve from Scilab, Using lpsolve from Octave, Using lpsolve from FreeMat, Using lpsolve from Euler, Using lpsolve from Python, Using lpsolve from Sage, Using lpsolve from PHP, Using lpsolve from R
doc/quickstart.htm 0000644 0001750 0001750 00000023230 11236130514 013167 0 ustar rene rene
Quick Startlp_solve (or lpsolve) has allot of features in-house. For a beginner, it can be difficult to determine where to start. The distribution contains many files and to start with, you need only a couple of them. As you learn the package you may need extras. This text explains how to start with lp_solve. Skip the blabla, just give me a very quick start.How to call lp_solveBasically, lp_solve is a library, a set of routines, called the API that can be called from almost any programming language to solve MILP problems. There are several ways to pass the data to the library:
Via the APIThe API is a set of routines that can be called from a programming language to build the model in memory, solve it and return the results. There are many API routines to perform many possible tasks and set several options. See lp_solve API reference for an overview.Via input filesStandard, lp_solve supports several input files types.
The common known MPS format (see mps-format) is supported by most solvers, but
it is not very readable for humans. Another format is the lp format (see lp-format)
that is more readable. lp_solve has the unique ability to use user-written routines to input the model
(see External Language Interface).
See read_mps, read_freemps, read_MPS, read_freeMPS and read_lp, read_LP for
the API calls to read the model from file. Via an IDEThanks to Henri Gourvest, there is now also an IDE program called LPSolve IDE that uses the API to provide a Windows application to solve models. See LPSolve IDE for its usage. With this program you don't have to know anything of API or computer programming languages. You can just provide your model to the program and it will solve the model and give you the result. As already stated, lp_solve can be called from many programming language. Among them are C, C++, Pascal, Delphi, Java, VB, C#, VB.NET, Excel. But let this list not be a limitation. Any programming language capable of calling external libraries (DLLs under Windows, Shared libraries (.so) under Unix/Linux) can call lp_solve. Some key features of lp_solve
Quick quick startFormulating a problemIf you don't know much about linear programming, first take a look at Formulation of an lp problem in lpsolve. Start with reading the first part where a practical example is presented until the point where the formulation is given in mathematical format, then return to here. This practical example is used in the next presentations. Another very usefull and free paper about linear programming fundamentals and advanced features plus several problems being discussed and modeled is Applications of optimization with Xpress-MP. It describes linear programming and modeling with the commercial solver Xpress-MP, but is as usefull for other solvers like lp_solve. In case that this link would not work anymore, try this via google search. Solve a problem via the IDEThe easiest way to start with lp_solve is via the IDE. This only works under Windows. See LPSolve IDE. Solve a problem via the lp_solve command line programAnother way to solve a model is via the lp_solve command line program. This works on any platform, but is completely command-line driven. Well known by Unix/Linux shell programmers and DOS box users. See lp_solve command. solve a problem via the APIProgrammers want to call lp_solve in a totally different way. They want to call lp_solve as a library directly from their programming language. This is what is called the API (Application Programming Interface). See Calling the lpsolve API from your application and Construct the model from a Programming Language. An overview of the complete API can be found on: lp_solve API reference. Compile the source code yourselfThe distribution contains precompiled libraries/binaries for Windows and Linux. However lp_solve can be compiled on other platforms also. You may also to make modifications to it and then you have to recompile also, even on the precompiled platforms. See Calling the lpsolve API from your application. In this article it is both explained how to link your code to the library and how to compile the lp_solve code. Basis Factorization PackagesAlternative inverse/re-factorization libraries can be used by lp_solve. This is a feature for the more experienced users of lp_solve. See Basis Factorization Packages for more information. The sources of these packages are in the lp_solve_5.5.0.15_bfp_*_source.tar.gz archives. The binaries are in the lp_solve_5.5.0.15_exe* archive. External Language InterfacesAlternative model readers and writers possible via the XLI implementation. Models expressed in format files other than lp or MPS format can also be read or written by lp_solve via this unique feature. See External Language Interfaces for more information. The sources of these packages are in the lp_solve_5.5.0.15_xli_*_source.tar.gz archives. The binaries are in the lp_solve_5.5.0.15_exe* archive. Calling lp_solve from higher level Mathematical languages.lp_solve can be called from AMPL, MATLAB, O-Matrix, Sysquake, Scilab, Octave, FreeMat, Euler, Python, Sage, PHP, R.You now have a pretty good idea what lp_solve is about. |
Linear programming basicsA short explanation is given what Linear programming is and some basic knowledge you need to know. A linear programming problem is mathematically formulated as follows:
The problem is usually expressed in matrix form, and then becomes: maximize CT x subject to A x <= B x >= 0 So a linear programming model consists of one objective which is a linear equation that must be maximized or minimized. Then there are a number of linear inequalities or constraints. cT, A and B are constant matrixes. x are the variables (unknowns). All of them are real, continue values. Note the default lower bounds of zero on all variables x. People tend to forget this build-in default. If no negative (or negative infinite) lower bound is explicitely set on variables, they can and will take only positive (zero included) values. The inequalities can be <=, >= or = Also note that both objective function and constraints must be linear equations. This means that no variables can be multiplied with each other. This formulation is called the Standard form. It is the usual and most intuitive form of describing a linear programming problem. Example: minimize 3 x1 - x2 subject to -x1 + 6 x2 - x3 + x4 >= -3 7 x2 + 2 x4 = 5 x1 + x2 + x3 = 1 x3 + x4 <= 2 Sometimes, these problems are formulated in the canonical form. All inequalities are converted to equalities by adding an extra variable where needed: maximize CT x subject to A x = B x >= 0 Above example can then be written as: minimize 3 x1 - x2 subject to -x1 + 6 x2 - x3 + x4 - s = -3 7 x2 + 2 x4 = 5 x1 + x2 + x3 = 1 x3 + x4 + t = 2 So everywhere an equality was specified, an extra variable is introduced and subtracted (if it was >) or added (if it was <) to the constraint. These variables also only take positive (or zero) values only. These extra variables are called slack or surplus variables. lp_solve add's these variables automatically to its internal structure. The formulator doesn't have to do it and it is even better not to. There will be fewer variables in the model and thus quicker to solve. See Formulation of an lp problem in lpsolve for a practical example. The right hand side (RHS), the B-vector, must be a constant matrix. Some people see this as a problem, but it isn't The RHS can always be brought to the left by a simple operation: A x <= BIs equal to: A x - B <= 0So if B is not constant, just do that. Basic mathematics also states that if a constraint is multiplied by a negative constant, that the inequality changes from direction. For example: 5 x1 - 2 x2 >= 3If multiplied by -1, it becomes: -5 x1 + 2 x2 <= -3 If the objective is multiplied by -1, then maximization becomes minimization and the other way around. For example: minimize 3 x1 - x2Can also be written as: maximize -3 x1 + x2 The result will be the same, but changed from sign. BoundsMinima and maxima on single variables are special cases of restrictions. They are called bounds. The optimization algorithm can handle these bounds more effeciently than other restrictions. They consume less memory and the algorithm is faster with them. As already specified, there is by default an implicit lower bound of zero on each variable. Only when explicitly another lower bound is set, the default of 0 is overruled. This other bound can be negative also. There is no default upper bound on variables. Almost all solvers support bounds on variables. So does lp_solve. RangesFrequently, it happens that on the same equation a less than and a greater than restriction must be set. Instead of adding two extra restrictions to the model, it is more performant and less memory consument to only add one restiction with either the less than or greater than restriction and put the other inequality on that same constraint by means of a range. Not all solvers support this feature but lp_solve does. Integer and binary variablesBy default, all variables are real. Sometimes it is required that one or more variables must be integer. It is not possible to just solve the model as is and then round to the nearest solution. At best, this result will maybe furfill all constraints, but you cannot be sure of. As you cannot be sure of the fact that this is the most optimal solution. Problems with integer variables are called integer or descrete programming problems. If all variables are integer it is called a pure integer programming problem, else it is a mixed integer programming problem. A special case of integer variables are binary variables. These are variables that can only take 0 or 1 as value. They are used quite frequently to program discontinue conditions. lp_solve can handle integer and binary variables. Binary variables are defined as integer variables with a maximum (upper bound) of 1 on them. See integer variables for a description on them. Semi-continuous variablesSemi-continuous variables are variables that must take a value between their minimum and maximum or zero. So these variables are treated the same as regular variables, except that a value of zero is also accepted, even if there is a minimum bigger than zero is set on the variable. See semi-continuous variables for a description on them. Special ordered sets (SOS)A specially ordered set of degree N is a collection of variables where at most N variables may be non-zero. The non-zero variables must be contiguous (neighbours) sorted by the ascending value of their respective unique weights. In lp_solve, specially ordered sets may be of any cardinal type 1, 2, and higher, and may be overlapping. The number of variables in the set must be equal to, or exceed the cardinal SOS order. See Special ordered sets (SOS) for a description on them. lp_solve uses the simplex algorithm to solve these problems. To solve the integer restrictions, the branch and bound (B&B) method is used. Other resourcesAnother very usefull and free paper about linear programming fundamentals and advanced features plus several problems being discussed and modeled is Applications of optimization with Xpress-MP. It describes linear programming and modeling with the commercial solver Xpress-MP, but is as usefull for other solvers like lp_solve. In case that this link would not work anymore, try this via google search. |
get_anti_degenReturns the used degeneracy rule. int get_anti_degen(lprec *lp); Return Value get_anti_degen returns the used degeneracy rule. Can be a combination of any of the following values:
Parameters lp Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI Remarks The get_anti_degen function returns the used degeneracy rule. Example
See Also make_lp, copy_lp, read_lp, read_LP, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, set_anti_degen, is_anti_degen |
read_lp, read_LPCreate an lprec structure and read an lp model from file. lprec *read_lp(FILE *stream, int verbose, char *lp_name); lprec *read_LP(char *filename, int verbose, char *lp_name); Return Value
Returns a pointer to a new lprec structure. This must be provided to almost all
lp_solve functions. Parameters stream Pointer to FILE structure. filename Filename to read the lp model from. verbose The verbose level. Can be one of the following values: See also set_verbose and get_verbose. lp_name Initial name of the model. See also set_lp_name and get_lp_name. May be NULL if the model has no name. Remarks The read_lp and read_LP functions construct a new lprec structure and read the model from filename. read_lp needs a file pointer to an already opened file. read_LP accepts the name of the file. The latter function will generally be more convenient.
The model in the file must be in lp-format.
Example
See Also delete_lp, free_lp, make_lp, copy_lp, write_lp, write_LP, write_lpex, read_mps, read_freemps, read_MPS, read_freeMPS, read_XLI, write_mps, write_freemps, write_MPS, write_freeMPS, MPS_writefileex |