File: set_row.htm

package info (click to toggle)
lp-solve 5.5.2.5-2
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye
  • size: 9,468 kB
  • sloc: ansic: 49,352; javascript: 2,025; yacc: 672; sh: 93; makefile: 84
file content (111 lines) | stat: -rw-r--r-- 5,913 bytes parent folder | download | duplicates (5)
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<HEAD>
		<TITLE>set_row, set_rowex</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>set_row, set_rowex</h1>
					<p>set a constraint in the lp.</p>
					<p><b>unsigned char set_row(lprec </b>*<i>lp</i><b>, int </b><i>row_no</i><b>, REAL </b>*<i>row</i><b>);</b></p>
					<p><b>unsigned char set_rowex(lprec </b>*<i>lp</i><b>, int </b><i>row_no</i><b>, int </b><i>count</i><b>, REAL </b>*<i>row</i><b>, int </b>*<i>colno</i><b>);</b></p>
					<p class="label"><b>Return Value</b></p>
					<p><b>set_row</b>, <b>set_rowex</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>row_no</i></p>
					<p class="indent">The row number that must be changed.</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 set_rowex, 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="label"><b>Remarks</b></p>
					<p>The <b>set_row</b>, <b>set_rowex</b> functions change the values of an existing row in the
						model at once.<br>
						<br>
						Note that <A HREF="add_constraint.htm">add_constraint, add_constraintex, str_add_constraint</A>
						<b>add</b> a row to the model, making the number of rows one larger. These functions <b>change</b> an <b>existing</b> row.<br>
						<br>
						Note that for <b>set_row</b> (and <b>set_rowex</b> when <i>colno</i> is
						NULL) element 1 of the array is column 1, element 2 is column 2, ... element 0 is <b>not</b> used.<br>
						<br>
						<b>set_rowex</b> has the possibility to specify only the non-zero elements. And in contrary to <b>set_row</b>,
						<b>set_rowex</b> reads the arrays starting from element 0. However when <i>colno</i> is NULL then
						<b>set_rowex</b> acts as <b>set_row</b> and then values start at element 1.
						When <i>colno</i> is provided, then it specifies the column numbers of the non-zero elements.
						This will speed up building the model considerably if there are a lot of zero values.<br>
						<br>
						In most cases the matrix is sparse and has many zero value. Thus it is almost always
						better to use <b>set_rowex</b> instead of <b>set_row</b>. <b>set_rowex</b>
						is always at least as performant as <b>set_row</b>.<br>
						<br>
						It is more performant to call these functions than multiple times <A HREF="set_mat.htm">set_mat</A>.<br>
						<br>
						Note that unspecified values by <b>set_rowex</b> are set to zero.<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>
					</p>
					<p class="label"><b>Example</b></p>
					<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#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(2, 3);
  if(lp == NULL) {
    fprintf(stderr, "Unable to create new LP model\n");
    return(1);
  }

  row[1] = 1.0;
  row[2] = 0.0; /* also zero elements must be provided */
  row[3] = 2.0;
  set_row(lp, 1, row); /* changes the values of existing row 1 */
  
  colno[0] = 1; sparserow[0] = 1.0; /* column 1 */
  colno[1] = 3; sparserow[1] = 2.0; /* column 3 */
  set_rowex(lp, 2, 2, sparserow, colno);

  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="get_row.htm">get_row, get_rowex</A>, <A HREF="add_constraint.htm">add_constraint, add_constraintex, str_add_constraint</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="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_mat.htm">get_mat</A></p>
				</TD>
			</TR>
		</TABLE>
	</BODY>
</html>