/usr/share/doc/lp-solve-doc/add_constraint.htm is in lp-solve-doc 5.5.0.15-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<HEAD>
<TITLE>add_constraint, add_constraintex, str_add_constraint</TITLE>
<style TYPE="text/css"> BODY { font-family:verdana,arial,helvetica; margin:0; }
</style>
</HEAD>
<BODY>
<TABLE class="clsContainer" style="TABLE-LAYOUT: fixed" cellSpacing="0" cellPadding="15"
width="100%" border="0">
<TR>
<TD vAlign="top">
<h1>add_constraint, add_constraintex, str_add_constraint</h1>
<p>Add a constraint to the lp.</p>
<p><b>unsigned char add_constraint(lprec </b>*<i>lp</i><b>, REAL </b>*<i>row</i><b>, int </b><i>constr_type</i><b>, REAL </b><i>rh</i><b>);</b></p>
<p><b>unsigned char add_constraintex(lprec </b>*<i>lp</i><b>, int </b><i>count</i><b>, REAL </b>*<i>row</i><b>, int </b>*<i>colno</i><b>, int </b><i>constr_type</i><b>, REAL </b><i>rh</i><b>);</b></p>
<p><b>unsigned char str_add_constraint(lprec </b>*<i>lp</i><b>, char </b>*<i>row_string</i><b>, int </b><i>constr_type</i><b>, REAL </b><i>rh</i><b>);</b></p>
<p class="label"><b>Return Value</b></p>
<p><b>add_constraint</b>, <b>add_constraintex</b> and <b>str_add_constraint</b> return TRUE (1) if the
operation was successful. A return value of FALSE (0) indicates an error.
</p>
<p class="label"><b>Parameters</b></p>
<p class="dt"><i>lp</i></p>
<p class="indent">Pointer to previously created lp model. See return value of <A href="make_lp.htm">
make_lp</A>, <A HREF="copy_lp.htm">copy_lp</A>, <A href="read_lp.htm">read_lp, read_LP</A>, <A href="read_mps.htm">read_mps, read_freemps, read_MPS, read_freeMPS</A>, <A HREF="read_XLI.htm">read_XLI</A></p>
<p class="dt"><i>count</i></p>
<p class="indent">Number of elements in <i>row</i> and <i>colno</i>.</p>
<p class="dt"><i>row</i></p>
<p class="indent"> An array with 1+<A href="get_Ncolumns.htm">get_Ncolumns</A> (<i>count</i> for add_constraintex, if <I>colno</I> is different from NULL) elements that
contains the values of the row.</p>
<p class="dt"><i>colno</i></p>
<p class="indent">A zero-based array with <i>count</i> elements that contains the column numbers
of the row. However this variable can also be NULL.
In that case element i in the variable <I>row</I> is column i and values start at element 1.
</p>
<p class="dt"><i>row_string</i></p>
<p class="indent">A string with column elements that contains the values of the
row. Each element must be separated by space(s).</p>
<p class="dt"><i>constr_type</i></p>
<p class="indent">The type of the constraint. Can by any of the following values:</p>
<TABLE id="Table2" cellSpacing="1" cellPadding="1" width="100%" border="1">
<TR>
<TD>LE (1)</TD>
<TD>Less than or equal (<=)</TD>
</TR>
<TR>
<TD>EQ (3)</TD>
<TD>Equal (=)</TD>
</TR>
<TR>
<TD>GE (2)</TD>
<TD>Greater than or equal (>=)</TD>
</TR>
</TABLE>
<p class="dt"><i>rh</i></p>
<p class="indent">The value of the right hand side (RHS).</p>
<p class="label"><b>Remarks</b></p>
<p>The <b>add_constraint</b>, <b>add_constraintex</b>, <b>str_add_constraint</b> functions add a row to the
model (at the end) and sets all values of the row at once.<br>
<br>
Note that for <b>add_constraint</b> (and <b>add_constraintex</b> when <i>colno</i> is
NULL) element 0 of the array is not considered (i.e. ignored). Column 1 is
element 1, column 2 is element 2, ...<br>
<br>
<b>str_add_constraint</b> should only be used in small or demo code since it is not performant and uses more memory.<br>
<br>
<b>add_constraintex</b> has the possibility to specify only the non-zero elements.
In that case <i>colno</i> specifies the column numbers of the non-zero elements.
Both <i>row</i> and <i>colno</i> are then zero-based arrays.
This will speed up building the model considerably if there are a lot of zero values.
In most cases the matrix is sparse and has many zero value.<br>
Note that <b>add_constraintex</b> behaves the same as <b>add_constraint</b> when <i>colno</i> is NULL.<br>
<br>
Thus it is almost always
better to use <b>add_constraintex</b> instead of <b>add_constraint</b>. <b>add_constraintex</b>
is always at least as performant as <b>add_constraint</b>.<br>
<br>
Note that it is advised to set the objective function
(via <A HREF="set_obj_fn.htm">set_obj_fn, set_obj_fnex, str_set_obj_fn, set_obj</A>)
before adding rows. This especially for larger models. This will be much more performant than adding the
objective function afterwards.<br>
<br>
Note that these routines will perform much better when <A HREF="set_add_rowmode.htm">set_add_rowmode</A>
is called before adding constraints.<br>
<br>
Note that if you have to add many constraints, performance can be improved by a call to
<A HREF="resize_lp.htm">resize_lp</A>.
</p>
<p class="label"><b>Example</b></p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include "lp_lib.h"
int main(void)
{
lprec *lp;
REAL row[1+3]; /* must be 1 more than number of columns ! */
REAL sparserow[2]; /* must be the number of non-zero values */
int colno[2];
/* Create a new LP model */
lp = make_lp(0, 3);
if(lp == NULL) {
fprintf(stderr, "Unable to create new LP model\n");
return(1);
}
set_add_rowmode(lp, TRUE);
row[1] = 1.0;
row[2] = 0.0; /* also zero elements must be provided */
row[3] = 2.0;
add_constraint(lp, row, GE, 3.0); /* constructs the row: +v_1 +2 v_3 >= 3 */
colno[0] = 1; sparserow[0] = 1.0; /* column 1 */
colno[1] = 3; sparserow[1] = 2.0; /* column 3 */
add_constraintex(lp, 2, sparserow, colno, GE, 3.0); /* constructs the row: +v_1 +2 v_3 >= 3 */
set_add_rowmode(lp, FALSE);
delete_lp(lp);
return(0);
}
</code></pre>
<p>
<A HREF="lp_solveAPIreference.htm">lp_solve API reference</A></p>
<p>
<b>See Also</b> <A HREF="make_lp.htm">make_lp</A>, <A HREF="copy_lp.htm">copy_lp</A>, <A HREF="copy_lp.htm">copy_lp</A>, <A href="read_lp.htm">read_lp,
read_LP</A>, <A HREF="read_mps.htm">
read_mps, read_freemps, read_MPS, read_freeMPS</A>, <A HREF="read_XLI.htm">read_XLI</A>, <A HREF="set_row.htm">set_row, set_rowex</A>, <A HREF="set_obj_fn.htm">set_obj_fn, set_obj_fnex, str_set_obj_fn,
set_obj</A>, <A HREF="set_add_rowmode.htm">set_add_rowmode</A>,
<A HREF="is_add_rowmode.htm">is_add_rowmode</A>, <A HREF="resize_lp.htm">resize_lp</A>, <A HREF="get_constr_type.htm">get_constr_type</A>,
<A HREF="is_constr_type.htm">is_constr_type</A>, <A HREF="del_constraint.htm">
del_constraint</A>, <A HREF="add_column.htm">add_column, add_columnex,
str_add_column</A>, <A HREF="set_column.htm">set_column, set_columnex</A>, <A HREF="get_column.htm">get_column, get_columnex</A>, <A HREF="get_row.htm">
get_row, get_rowex</A>, <A HREF="get_mat.htm">get_mat</A></p>
</TD>
</TR>
</TABLE>
</BODY>
</html>
|