Set the weights on variables.

int set_varweights(lprec *lp, REAL *weights);

Return Value

set_varweights returns TRUE (1) if the operation was successful. A return value of FALSE (0) indicates an error.
lp->spx_status specifies what error occurred.



Pointer to previously created lp model. See return value of make_lp, copy_lp, read_lp, read_lp_file, read_LP, read_mps, read_MPS


The weights array.


The set_varweights sets a weight factor on each variable. This is only used for the integer variables in the branch-and-bound algorithm. Array members are unique, real-valued numbers indicating the "weight" of the variable at the given index. The array is 1-based. So variable 1 is at index 1, variable 2 at index 2. Index 0 is not used. The array must contain get_Ncolumns elements.
The weights define which variable the branch-and-bound algorithm must select first. The lower the weight, the sooner the variable is chosen to make it integer.


#include <stdio.h>
#include <stdlib.h>
#include "lpkit.h"

int main(void)
  lprec *lp;
  REAL weights[1+2]; /* must be 1 more than number of columns */

  /* Create a new LP model */
  lp = make_lp(0, 2);
  if(lp == NULL) {
    fprintf(stderr, "Unable to create new LP model\n");

  weights[1] = 2;
  weights[2] = 1;

  set_varweights(lp, weights);


lp_solve API reference

See Also make_lp, copy_lp, read_lp, read_lp_file, read_LP, read_mps, read_MPS, get_varpriority, set_var_branch, get_var_branch, set_floor_first, get_floor_first