chiark / gitweb /
wip lp, problem setup compiles
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 7 Mar 2014 14:55:30 +0000 (14:55 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 7 Mar 2014 14:55:30 +0000 (14:55 +0000)
.gitignore
Makefile
main.c

index b25c15b81fae06e1c55946ac6270bfdb293870e8..de69d765622449cc8c0bd2f39a4737434da0b6ca 100644 (file)
@@ -1 +1,2 @@
 *~
+main
index fa230a6cf45013c8b9a2721b11fde123b066ebb1..166f614380eaf5cf6406a7bfa3ef96716111aaa4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 CFLAGS += -Wall -Wwrite-strings -Wstrict-prototypes
 LC_CTYPE=C
-LDLIBS = -lpub
+LDLIBS = -lpub -lglpk
 
 all: main
diff --git a/main.c b/main.c
index e246752ef153b4272fb333f13e511fd05aa38252..22fa3437bfd7b7b7d3e43a2a25d69ea33a6ef26b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -2,9 +2,11 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <assert.h>
 #include <inttypes.h>
 
 #include <publib.h>
+#include <glpk.h>
 
 typedef uint32_t AdjWord;
 #define PRADJ "08"PRIx32
@@ -21,7 +23,7 @@ static void prep(void) {
 }
 
 static AdjWord one_adj_bit(int bitnum) {
-  return (AdjWord)1 << j;
+  return (AdjWord)1 << bitnum;
 }
 
 static int count_set_adj_bits(AdjWord w) {
@@ -32,7 +34,8 @@ static int count_set_adj_bits(AdjWord w) {
 }
 
 static void optimise(void) {
-  int i, totalfrags;
+  int i, j, totalfrags;
+
   for (i=0, totalfrags=0; i<n; i++) {
     int frags = count_set_adj_bits(adjmatrix[i]);
     totalfrags += frags;
@@ -70,14 +73,12 @@ static void optimise(void) {
 
   glp_prob *prob = glp_create_prob();
 
-  int Y_totals_i = glp_add_rows(prob, i);
-  int Y_totals_j = glp_add_rows(prob, j);
+  int Y_totals_i = glp_add_rows(prob, n);
+  int Y_totals_j = glp_add_rows(prob, m);
   int X_minimum = glp_add_cols(prob, 1);
-  int rows = glp_get_num_rows(prob);
-  int cols = glp_get_num_rows(cols);
 
   int next_matrix_entry = 1; /* wtf GLPK! */
-  int matrix_entries_size = next_matrix_entry + i + j + totalfrags*2;
+  int matrix_entries_size = next_matrix_entry + n + m + totalfrags*2;
   double matrix_entries[matrix_entries_size];
   int matrix_entries_XY[2][matrix_entries_size];
 
@@ -97,11 +98,11 @@ static void optimise(void) {
 
   /* \forall_i x_totals_i = m */
   /* \forall_i x_totals_j = n */
-  for (i=0; i<n; i++) glp_set_row_bounds(prob, Y_totals_i+i, GLP_FX, m,m);
-  for (j=0; j<m; j++) glp_set_row_bounds(prob, Y_totals_j+j, GLP_FX, n,n);
+  for (i=0; i<n; i++) glp_set_row_bnds(prob, Y_totals_i+i, GLP_FX, m,m);
+  for (j=0; j<m; j++) glp_set_row_bnds(prob, Y_totals_j+j, GLP_FX, n,n);
 
   /* x_minimum >= 0 */
-  glp_set_col_bounds(prob, X_minimum, GLP_LB, 0, 0);
+  glp_set_col_bnds(prob, X_minimum, GLP_LO, 0, 0);
 
   /* objective is maximising x_minimum */
   glp_set_obj_dir(prob, GLP_MAX);
@@ -131,10 +132,9 @@ static void optimise(void) {
 
   assert(next_matrix_entry == matrix_entries_size);
 
-  for (row=1; row<=rows; row++) {
-    glp_load_matrix(prob, next_matrix_entry,
-                   matrix_entries_XY[1], matrix_entries_XY[0],
-                   matrix_entries);
+  glp_load_matrix(prob, next_matrix_entry,
+                 matrix_entries_XY[1], matrix_entries_XY[0],
+                 matrix_entries);
 
   printf("nyi\n");
 }