1/* BEGIN LICENSE BLOCK 2 * Version: CMPL 1.1 3 * 4 * The contents of this file are subject to the Cisco-style Mozilla Public 5 * License Version 1.1 (the "License"); you may not use this file except 6 * in compliance with the License. You may obtain a copy of the License 7 * at www.eclipse-clp.org/license. 8 * 9 * Software distributed under the License is distributed on an "AS IS" 10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 11 * the License for the specific language governing rights and limitations 12 * under the License. 13 * 14 * The Original Code is The ECLiPSe Constraint Logic Programming System. 15 * The Initial Developer of the Original Code is Cisco Systems, Inc. 16 * Portions created by the Initial Developer are 17 * Copyright (C) 1997-2006 Cisco Systems, Inc. All Rights Reserved. 18 * 19 * Contributor(s): Joachim Schimpf, Kish Shen and Andrew Eremin, IC-Parc 20 * 21 * END LICENSE BLOCK */ 22 23#define PROBLEM_LP 0 /* these correspond to cplex_problem_code/2 */ 24#define PROBLEM_MIP 1 25#define PROBLEM_QP 2 26#define PROBLEM_MIQP 3 27#define PROBLEM_FIXEDL 4 28#define PROBLEM_FIXEDQ 5 29#define PROBLEM_RELAXEDL 6 30#define PROBLEM_RELAXEDQ 7 31 32#define METHOD_DEFAULT (-1) /* correspond to cplex_crossover_codes/3 */ 33#define METHOD_AUTO 0 34#define METHOD_PRIMAL 1 35#define METHOD_DUAL 2 36#define METHOD_NET 3 37#define METHOD_BAR 4 38#define METHOD_SIFT 5 39#define METHOD_CONCURRENT 6 40#define METHOD_CONCURRENTDET 7 41#define METHOD_NONE 8 42 43#define SENSE_MIN 1 /* these correspond to cplex_objsense/2 */ 44#define SENSE_MAX (-1) 45 46#define IsMIPProb(t) ((t) == PROBLEM_MIP || (t) == PROBLEM_MIQP) 47#define IsQPProb(t) ((t) == PROBLEM_QP || (t) == PROBLEM_MIQP) 48 49 50#ifdef SOLVE_MIP_COPY 51# define XP_COPYOFF 0 /* do not make copy of problem */ 52# define XP_COPYINVALID 1 /* copy of problem not valid */ 53# define XP_COPYCURRENT 2 /* copy of problem is current */ 54# define Mark_Copy_As_Modified(lpd) \ 55 if (lpd->copystatus != XP_COPYOFF) lpd->copystatus = XP_COPYINVALID 56#else 57# define Mark_Copy_As_Modified(lpd) {} 58#endif 59 60#if defined(NOECLIPSE) 61/* compiling for logged code */ 62 63# ifdef XPRESS 64# ifdef __STDC__ 65# define __ANSIC_ /* used in xpresso.h */ 66# endif 67# include "xprs.h" 68# include <stdio.h> 69# include <string.h> 70# define CPXLPptr XPRSprob 71# endif /* XPRESS */ 72 73# ifdef CPLEX 74# include "cplex.h" 75# include <stdio.h> 76# include <string.h> 77# endif /* CPLEX */ 78 79# ifdef C_TO_COIN 80# define COINprob void 81# endif /* COIN */ 82 83#endif /* NOECLIPSE */ 84 85 86/* position of stream types in solver_stream[]. 87 (for XPRESS, = message type - 1 */ 88#define LogType 0 /* log */ 89#define ResType 1 /* result */ 90#define WrnType 2 /* warning */ 91#define ErrType 3 /* error */ 92 93 94/* 95 * Our extended problem descriptor 96 */ 97 98 99typedef struct { 100 101 int descr_state; /* status DESCR_xxx */ 102 103 CPXLPptr lp; /* CPLEX/XPRESS handle */ 104 CPXLPptr lpcopy; /* copy of problem to allow MIP modifications */ 105 106#ifdef SOLVE_MIP_COPY 107 int copystatus; /* status of copy of problem */ 108#endif 109#ifdef USE_PROBLEM_ARRAY 110 int matno; /* XPRESS matrix number if descriptor not 111 current (or matrix number for logging) */ 112#endif 113 114 /* here we collect the input parameters for cplex */ 115 int prob_type; 116 int presolve; /* presolve for problem */ 117 int sense; /* objective sense min=1, max=-1 */ 118 int mac; /* number of valid colunms */ 119 int macadded; /* columns already added to solver */ 120 int start_mac; /* initial number of valid columns */ 121 int mar; /* number of valid rows */ 122 int nidc; /* number of indicator constraints */ 123 124 int matnz; /* used nonzeros in column-wise nz arrays */ 125 int macsz; /* size of column buffer arrays */ 126 int marsz; 127 double *rhsx; /* rhs coeff. initial matrix + added rows */ 128 char *senx; /* constraint sense initial matrix + added rows */ 129 /* CAUTION: uses external solver's encoding! */ 130 /* column-wise representation of matrix coefficients 131 initial matrix + added columns 132 */ 133 int *matbeg; /* index into matind for each column */ 134 int *matcnt; /* non-zeros count in each column */ 135 int *matind; /* non-zeros row indicies */ 136 double *matval; /* non-zeros coefficient */ 137 138 /* column information initial matrix + added columns */ 139 double *bdl; /* [macsz growable] */ 140 double *bdu; /* [macsz growable] */ 141 char dirtybdflag; /* bit-wise flag to indicate "dirty" bound arrays */ 142 char *ctype; /* column type */ 143 double *objx; /* objective coefficients */ 144 char *qgtype; /* [ngents] types of non-continuous vars */ 145 int *mgcols; /* [ngents] col-nos of non-continuous vars */ 146#ifdef XPRESS 147 char *probname; /* problem name (for XPRESS files) */ 148 int ngents; /* number of non-continuous vars */ 149#endif 150 151 int nsos; /* number of SOSs */ 152 int nsos_added; /* number of SOSs already in solver */ 153 int sossz; /* size of sos arrays */ 154 int sosnzsz; /* size of sos member arrays */ 155 int nsosnz; /* total number of sos members */ 156 sostype_t *sostype; /* [sosnzsz] sos type 1 or 2 */ 157 int *sosbeg; /* [sossz] index into sosind[] */ 158 int *sosind; /* [sosnzsz] col-no */ 159 double *sosref; /* [sosnzsz] */ 160 161 double *rngval; 162 char **cname; 163 char *cstore; 164 char **rname; 165 char *rstore; 166 unsigned cstorsz; 167 unsigned rstorsz; 168 169 /* A set of growable arrays, used as temporary storage for 170 * - setting up the quadratic objective coefficients 171 * - modifying linear objective coefficients 172 * - modifying quadratic objective coefficients 173 * These all use a sparse representation for columns 174 */ 175 int cb_sz; /* size of cb_... arrays */ 176 int cb_cnt; /* next index to be used */ 177 int *cb_index; /* [cb_sz] */ 178 int *cb_index2; /* [cb_sz] for quad obj setup only (may be NULL) */ 179 double *cb_value; /* [cb_sz] coeff value */ 180 181 /* to add constraints (and retrieve constraints) */ 182 int nr_sz; /* size of new row arrays */ 183 int nnz_sz; /* size of new nonzero arrays */ 184 int nr; /* next new row index */ 185 int nnz; /* next new nonzero index */ 186 int *rmatbeg; /* [nr_sz] nr_sz > nr! */ 187 int *rmatind; /* [nnz_sz] */ 188 double *rmatval; /* [nnz_sz] */ 189 char *rcompl; /* [nr_sz] indicator constraints only */ 190 int *rindind; /* [nr_sz] indicator constraints only */ 191 192 int numsz; /* auxiliary array for delrows/delcols */ 193 int *numbers; /* [numsz], contains numbers 0..numsz-1 */ 194 int *zeroes; /* [numsz], contains int zeroes */ 195 double *dzeroes; /* [numsz], contains double zeroes */ 196 197 /* cutpools - *2 variants are conditional */ 198/* int cp_nr_sz; /* size of cutpool row arrays */ 199 int cp_nr_sz2; /* size of cond cutpool row arrays */ 200/* int cp_nz_sz; /* size of cutpool nonzero arrays */ 201 int cp_nz_sz2; /* size of cond cutpool nonzero arrays */ 202/* int cp_nr; /* next cutpool row index */ 203 int cp_nr2; /* next cond cutpool row index */ 204/* int cp_nnz; /* next cuypool nonzero index */ 205 int cp_nnz2; /* next cond cutpool nonzero index */ 206 int cp_nact2; /* no. of active constraints in last solve */ 207/* int *cp_rmatbeg; /* [cp_nr_sz] */ 208 int *cp_rmatbeg2; /* [cp_nr_sz2] */ 209/* int *cp_rmatind; /* [cp_nz_sz] */ 210 int *cp_rmatind2; /* [cp_nz_sz2] */ 211/* double *cp_rmatval; /* [cp_nz_sz] */ 212 double *cp_rmatval2; /* [cp_nz_sz2] */ 213/* double *cp_rhsx; /* [cp_nr_sz] cutpool rhs coeffs */ 214 double *cp_rhsx2; /* [cp_nr_sz2] cond cutpool rhs coeffs */ 215/* char *cp_senx; /* [cp_nr_sz] cutpool constraint */ 216 char *cp_senx2; /* [cp_nr_sz2] cond cutpool constraint */ 217 /* CAUTION: uses external solver's encoding! */ 218 char *cp_active2; /* [cp_nr_sz2] default state */ 219 char *cp_initial_add2; /* [cp_nr_sz2] added initially or not */ 220 /* named conditional cutpools */ 221 int cp_npools2; 222 int cp_npools_sz2; 223 int *cp_pools_max2; /* [cp_npools_sz2] max cstr in each pool */ 224 int *cp_pools_sz2; /* [cp_npools_sz2] size for each pool */ 225 int **cp_pools2; /* [cp_npools_sz2] of int arrays of idxs */ 226 char **cp_names2; /* [cp_npools_sz2] of cutpool names */ 227 228 double objval; /* the most recent objective value */ 229 int sol_state; /* the most recent return status */ 230 231 int mipstart_dirty; /* we did set mipstart values */ 232 233 /* statistics for most recent solver call */ 234 int sol_itcnt; 235 int sol_nodnum; 236 237 /* (global) statistics */ 238 int optimum_ctr; 239 int infeas_ctr; 240 int abort_ctr; 241} lp_desc; 242 243 244/* 245 * Parameter descriptor array type 246 */ 247 248struct param_desc { 249 char * name; 250 param_id_t num; 251 int type; 252}; 253 254 255/* 256 * Solver method information 257 */ 258 259struct lp_meth { 260 int meth; 261 int auxmeth; 262 int node_meth; 263 int node_auxmeth; 264#ifdef XPRESS 265 char *meth_string; 266 char *node_meth_string; 267#endif 268 int option_mipstart; 269}; 270 271 272/* 273 * Container for problem solutions 274 */ 275 276struct lp_sol { 277 double *oldsols; /* [oldmac] */ 278 double *sols; /* [mac] */ 279 double *slacks; 280 double *pis; 281 double *djs; /* [mac] */ 282 int *cbase; /* [mac] */ 283 int *rbase; 284 int oldmac; 285 int mac; 286}; 287 288 289/* NOECLIPSE is defined if compiling the logged calls for bug reporting. 290 The calls are compiled without using ECLiPSe 291*/ 292 293#ifdef NOECLIPSE 294lp_desc *lpd; 295lp_desc *lpdmat[400]; /* change size if more lpd used */ 296 297double objval, bestbound, worstbound; 298int res,err; 299 300# ifdef XPRESS 301struct lp_sol sol; 302 303void XPRS_CC 304_get_xpress_sol(lp, solution) 305XPRSprob lp; 306void *solution; 307{ 308 struct lp_sol *sol = (struct lp_sol *) solution; 309 310 printf("Getting solution....\n"); 311 XPRSgetsol(lp, sol->sols, sol->slacks, sol->pis, sol->djs); 312 printf("Gotten solution....\n"); 313/* if (sol->base != NULL) 314 XPRSgetpresolvebasis(lp, sol->base, sol->base+sol->mac); 315*/ 316} 317 318XPRSprob cpx_env; 319 320# endif /* XPRESS */ 321#endif /* NOECLIPSE */ 322