This file is indexed.

/usr/include/libspreadsheet-1.12/spreadsheet/tools/gnm-solver.h is in gnumeric 1.12.18-2.

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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#ifndef _TOOLS_GNM_SOLVER_H_
#define _TOOLS_GNM_SOLVER_H_

#include <gnumeric.h>
#include <glib-object.h>
#include <dependent.h>
#include <numbers.h>
#include <wbc-gtk.h>

G_BEGIN_DECLS

/* ------------------------------------------------------------------------- */

typedef enum {
	GNM_SOLVER_RESULT_NONE,
	GNM_SOLVER_RESULT_FEASIBLE,
	GNM_SOLVER_RESULT_OPTIMAL,
	GNM_SOLVER_RESULT_INFEASIBLE,
	GNM_SOLVER_RESULT_UNBOUNDED
} GnmSolverResultQuality;


GType gnm_solver_status_get_type (void);
#define GNM_SOLVER_STATUS_TYPE (gnm_solver_status_get_type ())

typedef enum {
	GNM_SOLVER_STATUS_READY,
	GNM_SOLVER_STATUS_PREPARING,
	GNM_SOLVER_STATUS_PREPARED,
	GNM_SOLVER_STATUS_RUNNING,
	GNM_SOLVER_STATUS_DONE,
	GNM_SOLVER_STATUS_ERROR,
	GNM_SOLVER_STATUS_CANCELLED
} GnmSolverStatus;


typedef enum {
        GNM_SOLVER_LE,
	GNM_SOLVER_GE,
	GNM_SOLVER_EQ,
	GNM_SOLVER_INTEGER,
	GNM_SOLVER_BOOLEAN
} GnmSolverConstraintType;


typedef enum {
	GNM_SOLVER_LP, GNM_SOLVER_QP, GNM_SOLVER_NLP
} GnmSolverModelType;


GType gnm_solver_problem_type_get_type (void);
#define GNM_SOLVER_PROBLEM_TYPE_TYPE (gnm_solver_problem_type_get_type ())

typedef enum {
        GNM_SOLVER_MINIMIZE, GNM_SOLVER_MAXIMIZE
} GnmSolverProblemType;

/* -------------------------------------------------------------------------- */

struct GnmSolverConstraint_ {
	GnmSolverConstraintType type;

	/* Must be a range.  */
	GnmDependent lhs;

	/* Must be a constant or a range.  */
	GnmDependent rhs;
};

GnmSolverConstraint *gnm_solver_constraint_new (Sheet *sheet);
void gnm_solver_constraint_free (GnmSolverConstraint *c);
GnmSolverConstraint *gnm_solver_constraint_dup (GnmSolverConstraint *c,
						Sheet *sheet);
gboolean gnm_solver_constraint_equal (GnmSolverConstraint const *a,
				      GnmSolverConstraint const *b);

void gnm_solver_constraint_set_old (GnmSolverConstraint *c,
				    GnmSolverConstraintType type,
				    int lhs_col, int lhs_row,
				    int rhs_col, int rhs_row,
				    int cols, int rows);

gboolean gnm_solver_constraint_has_rhs (GnmSolverConstraint const *c);
gboolean gnm_solver_constraint_valid (GnmSolverConstraint const *c,
				      GnmSolverParameters const *sp);
gboolean gnm_solver_constraint_get_part (GnmSolverConstraint const *c,
					 GnmSolverParameters const *sp, int i,
					 GnmCell **lhs, gnm_float *cl,
					 GnmCell **rhs, gnm_float *cr);

GnmValue const *gnm_solver_constraint_get_lhs (GnmSolverConstraint const *c);
GnmValue const *gnm_solver_constraint_get_rhs (GnmSolverConstraint const *c);

void gnm_solver_constraint_set_lhs (GnmSolverConstraint *c, GnmValue *v);
void gnm_solver_constraint_set_rhs (GnmSolverConstraint *c, GnmValue *v);

void gnm_solver_constraint_side_as_str (GnmSolverConstraint const *c,
					Sheet const *sheet,
					GString *buf, gboolean lhs);
char *gnm_solver_constraint_as_str (GnmSolverConstraint const *c, Sheet *sheet);

/* ------------------------------------------------------------------------- */

typedef struct {
	int                 max_time_sec;
	int                 max_iter;
	GnmSolverFactory   *algorithm;
	GnmSolverModelType  model_type;
	gboolean            assume_non_negative;
	gboolean            assume_discrete;
	gboolean            automatic_scaling;
	gboolean            program_report;
	gboolean            add_scenario;
	gchar               *scenario_name;
} GnmSolverOptions;

#define GNM_SOLVER_PARAMETERS_TYPE   (gnm_solver_param_get_type ())
#define GNM_SOLVER_PARAMETERS(o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNM_SOLVER_PARAMETERS_TYPE, GnmSolverParameters))
#define GNM_IS_SOLVER_PARAMETERS(o)  (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SOLVER_PARAMETERS_TYPE))

struct GnmSolverParameters_ {
	GObject parent;

	/* Default parsing sheet.  No ref held.  */
	Sheet *sheet;

	GnmSolverProblemType problem_type;
	GnmDependent target;
	GnmDependent input;
	GSList *constraints;
	GnmSolverOptions options;
};

typedef struct {
	GObjectClass parent_class;
} GnmSolverParametersClass;

GType gnm_solver_param_get_type (void);

/* Creates a new GnmSolverParameters object. */
GnmSolverParameters *gnm_solver_param_new (Sheet *sheet);

/* Duplicate a GnmSolverParameters object. */
GnmSolverParameters *gnm_solver_param_dup (GnmSolverParameters *src_param,
					   Sheet *new_sheet);

gboolean gnm_solver_param_equal (GnmSolverParameters const *a,
				 GnmSolverParameters const *b);

GnmValue const *gnm_solver_param_get_input (GnmSolverParameters const *sp);
void gnm_solver_param_set_input (GnmSolverParameters *sp, GnmValue *v);
GSList *gnm_solver_param_get_input_cells (GnmSolverParameters const *sp);

const GnmCellRef *gnm_solver_param_get_target (GnmSolverParameters const *sp);
void gnm_solver_param_set_target (GnmSolverParameters *sp,
				  GnmCellRef const *cr);
GnmCell *gnm_solver_param_get_target_cell (GnmSolverParameters const *sp);

void gnm_solver_param_set_algorithm (GnmSolverParameters *sp,
				     GnmSolverFactory *algo);

gboolean gnm_solver_param_valid (GnmSolverParameters const *sp, GError **err);

/* -------------------------------------------------------------------------- */

#define GNM_SOLVER_RESULT_TYPE   (gnm_solver_result_get_type ())
#define GNM_SOLVER_RESULT(o)     (G_TYPE_CHECK_INSTANCE_CAST ((o), GNM_SOLVER_RESULT_TYPE, GnmSolverResult))

typedef struct {
	GObject parent;

	GnmSolverResultQuality quality;

	/* Objective value, if any */
	gnm_float value;

	/* Array value of solution, if any */
	GnmValue *solution;
} GnmSolverResult;

typedef struct {
	GObjectClass parent_class;
} GnmSolverResultClass;

GType gnm_solver_result_get_type (void);

/* ------------------------------------------------------------------------- */
/* Generic Solver class. */

#define GNM_SOLVER_TYPE        (gnm_solver_get_type ())
#define GNM_SOLVER(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), GNM_SOLVER_TYPE, GnmSolver))
#define GNM_SOLVER_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST ((k), GNM_SOLVER_TYPE, GnmSolverClass))
#define GNM_IS_SOLVER(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SOLVER_TYPE))

typedef struct {
	GObject parent;

	GnmSolverStatus status;
	char *reason;

	GnmSolverParameters *params;
	GnmSolverResult *result;
	double starttime, endtime;
} GnmSolver;

typedef struct {
	GObjectClass parent_class;

	gboolean (*prepare) (GnmSolver *solver,
			     WorkbookControl *wbc, GError **err);
	gboolean (*start) (GnmSolver *solver,
			   WorkbookControl *wbc, GError **err);
	gboolean (*stop) (GnmSolver *solver, GError **err);
	void (*child_exit) (GnmSolver *solver, gboolean normal, int code);
} GnmSolverClass;

GType gnm_solver_get_type  (void);

gboolean gnm_solver_prepare (GnmSolver *solver,
			     WorkbookControl *wbc, GError **err);
gboolean gnm_solver_start (GnmSolver *solver,
			   WorkbookControl *wbc, GError **err);
gboolean gnm_solver_stop (GnmSolver *solver, GError **err);

void gnm_solver_set_status (GnmSolver *solver, GnmSolverStatus status);

void gnm_solver_set_reason (GnmSolver *solver, const char *reason);

void gnm_solver_store_result (GnmSolver *solver);

void gnm_solver_create_report (GnmSolver *solver, const char *name);

double gnm_solver_elapsed (GnmSolver *solver);

gboolean gnm_solver_check_timeout (GnmSolver *solver);

gboolean gnm_solver_finished (GnmSolver *solver);

gboolean gnm_solver_has_solution (GnmSolver *solver);

gboolean gnm_solver_check_constraints (GnmSolver *solver);

GnmValue *gnm_solver_get_current_values (GnmSolver *solver);

gboolean gnm_solver_saveas (GnmSolver *solver, WorkbookControl *wbc,
			    GOFileSaver *fs,
			    const char *templ, char **filename,
			    GError **err);

gboolean gnm_solver_debug (void);

/* ------------------------------------------------------------------------- */
/* Solver subclass for subprocesses. */

#define GNM_SUB_SOLVER_TYPE     (gnm_sub_solver_get_type ())
#define GNM_SUB_SOLVER(o)       (G_TYPE_CHECK_INSTANCE_CAST ((o), GNM_SUB_SOLVER_TYPE, GnmSubSolver))
#define GNM_SUB_SOLVER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNM_SUB_SOLVER_TYPE, GnmSubSolverClass))
#define GNM_IS_SUB_SOLVER(o)    (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SUB_SOLVER_TYPE))

typedef struct {
	GnmSolver parent;

	char *program_filename;

	/* Hashes between char* and cell*.  */
	GHashTable *cell_from_name;
	GHashTable *name_from_cell;

	GPid child_pid;
	guint child_watch;

	gint fd[3];
	GIOChannel *channels[3];
	guint channel_watches[3];
	GIOFunc io_funcs[3];
	gpointer io_funcs_data[3];
} GnmSubSolver;

typedef struct {
	GnmSolverClass parent_class;
} GnmSubSolverClass;

GType gnm_sub_solver_get_type  (void);

void gnm_sub_solver_clear (GnmSubSolver *subsol);

gboolean gnm_sub_solver_spawn
		(GnmSubSolver *subsol,
		 char **argv,
		 GSpawnChildSetupFunc child_setup, gpointer setup_data,
		 GIOFunc io_stdout, gpointer stdout_data,
		 GIOFunc io_stderr, gpointer stderr_data,
		 GError **err);

void gnm_sub_solver_flush (GnmSubSolver *subsol);

const char *gnm_sub_solver_name_cell (GnmSubSolver *subsol,
				      GnmCell const *cell,
				      const char *name);
GnmCell *gnm_sub_solver_find_cell (GnmSubSolver *subsol, const char *name);
const char *gnm_sub_solver_get_cell_name (GnmSubSolver *subsol,
					  GnmCell const *cell);

char *gnm_sub_solver_locate_binary (const char *binary, const char *solver,
				    const char *url,
				    WBCGtk *wbcg);

/* ------------------------------------------------------------------------- */

#define GNM_SOLVER_FACTORY_TYPE        (gnm_solver_factory_get_type ())
#define GNM_SOLVER_FACTORY(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), GNM_SOLVER_FACTORY_TYPE, GnmSolverFactory))
#define GNM_IS_SOLVER_FACTORY(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNM_SOLVER_FACTORY_TYPE))

typedef GnmSolver * (*GnmSolverCreator) (GnmSolverFactory *,
					 GnmSolverParameters *);
typedef gboolean (*GnmSolverFactoryFunctional) (GnmSolverFactory *,
						WBCGtk *);

struct GnmSolverFactory_ {
	GObject parent;

	char *id;
	char *name; /* Already translated */
	GnmSolverModelType type;
	GnmSolverCreator creator;
	GnmSolverFactoryFunctional functional;
};

typedef struct {
	GObjectClass parent_class;
} GnmSolverFactoryClass;

GType gnm_solver_factory_get_type (void);

GnmSolverFactory *gnm_solver_factory_new (const char *id,
					  const char *name,
					  GnmSolverModelType type,
					  GnmSolverCreator creator,
					  GnmSolverFactoryFunctional funct);
GnmSolver *gnm_solver_factory_create (GnmSolverFactory *factory,
				      GnmSolverParameters *param);
gboolean gnm_solver_factory_functional (GnmSolverFactory *factory,
					WBCGtk *wbcg);

GSList *gnm_solver_db_get (void);
void gnm_solver_db_register (GnmSolverFactory *factory);
void gnm_solver_db_unregister (GnmSolverFactory *factory);

/* ------------------------------------------------------------------------- */

G_END_DECLS

#endif /* _TOOLS_GNM_SOLVER_H_ */