├── BidSet.cpp ├── BidSet.h ├── Distribution.cpp ├── Distribution.h ├── Legacy.cpp ├── Legacy.h ├── Makefile ├── Param.cpp ├── Param.h ├── README.md ├── arbitrary.cpp ├── arbitrary.h ├── bid.cpp ├── bid.h ├── cats.exe ├── debugobj └── Makefile ├── default_dist_dist ├── default_model_file ├── featureCalc.cpp ├── featureCalc.h ├── lp_solve_4.0 ├── .cvsignore ├── CHANGELOG ├── HARTMUT_DOCUMENTATION ├── LGPL.txt ├── LICENSE ├── MANIFEST ├── MIPLIB_RESULTS ├── MPS.description ├── Makefile ├── Makefile.linux ├── Makefile.msc ├── Makefile.sco5 ├── Makefile.unix ├── NETLIB_RESULTS ├── README ├── SOSInterpolation.pdf ├── debug.c ├── debug.h ├── declare.h ├── demo.c ├── fortify.c ├── fortify.h ├── hash.c ├── hash.h ├── lex.l ├── lp.y ├── lp2mps.c ├── lp_solve.1 ├── lp_solve.c ├── lp_solve.man ├── lpglob.h ├── lpkit.c ├── lpkit.h ├── lpsolve.rc ├── mps2lp.c ├── patchlevel.h ├── presolve.c ├── read.c ├── read.h ├── readmps.c ├── resource.h ├── solve.c ├── ufortify.h ├── windll.c └── windll.def ├── main.cpp ├── matching.cpp ├── matching.h ├── normal.cpp ├── normal.h ├── obj └── Makefile ├── paths.cpp ├── paths.h ├── polyModel.cpp ├── polyModel.h ├── qpstuff ├── L2-qp.txt ├── L3-qp.txt ├── L4-qp.txt ├── L6-qp.txt ├── L7-qp.txt ├── arbitrary-npv-qp.txt ├── arbitrary-upv-qp.txt ├── cass-qp.txt ├── cplex-qp.txt ├── lehman-qp.txt ├── matching-qp.txt ├── regions-npv-qp.txt ├── regions-upv-qp.txt └── scheduling-qp.txt ├── regions.cpp ├── regions.h ├── scheduling.cpp ├── scheduling.h └── uniform_hybrid /BidSet.h: -------------------------------------------------------------------------------- 1 | /* INPUT FILE FORMAT: 2 | 3 | ================== 4 | 5 | % comments follow percentage symbols 6 | % blank lines are ignored 7 | % files are not case-sensitive 8 | % [CR]'s are optional, all whitespace is ignored 9 | 10 | goods 15 11 | dummy 10 12 | bids 800 13 | 14 | % bidnum, price, goodnum, goodnum, ..., goodnum, # 15 | 0 20.75 2 6 8 # 16 | 1 30 1 2 5 7 13 # 17 | 2 5.20 4 # 18 | . 19 | . 20 | . 21 | 22 | % implicitly, all goods numbered 15 or above (in this example) are dummies 23 | % note that all counting starts from zero 24 | % bidnum's do not need to be sequential between 0..799. They just need to be unique. 25 | */ 26 | 27 | #ifdef WIN32 28 | #pragma warning (disable : 4786) 29 | #endif 30 | 31 | #ifndef BidSet_H 32 | #define BidSet_H 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | using namespace std; 40 | 41 | #include "bid.h" 42 | #include "Param.h" 43 | #include "Distribution.h" 44 | 45 | class BidSet { 46 | public: 47 | void refine(); 48 | void compact(); 49 | bool parse(char *filename); 50 | void parse(); 51 | 52 | // functions 53 | void print(int maxrec = -1); 54 | void writeCPLEXFile(Param &p, int index = 0); 55 | void writeOutput(Param &p, Distribution *d, int index = 0); 56 | 57 | bool isConnected(); 58 | int numComponents(); 59 | int *disconnectedBids; 60 | int numDisconnectedBids; 61 | void makeBidGraph(void); 62 | 63 | // constructors/destructor 64 | BidSet(const int num_goods = 0, int init_array_size = 100, bool deleteRemovedBids = true); 65 | BidSet(const BidSet& orig); 66 | BidSet(const char *filename, bool deleteRemovedBids = true); 67 | ~BidSet(); 68 | 69 | // VCC apparently doesn't use copy constructor for assignment 70 | BidSet& operator=(const BidSet& orig); 71 | 72 | // bid access functions 73 | void removeBid(int index); 74 | void add(Bid *added_bid, bool doRefine); 75 | void addXor(Bid *added_bid); 76 | void doneAddingXor(bool run_refine); 77 | 78 | inline int numBids() { 79 | return num_bids; 80 | } 81 | 82 | inline int numGoods() { 83 | return num_goods; 84 | } 85 | 86 | inline int numDummyGoods() { 87 | return num_dummy_items; 88 | } 89 | 90 | inline Bid *getBid(int index) { 91 | return bid[index]; 92 | } 93 | 94 | map > *getGoodMap(void) { 95 | return &goodMap; 96 | } 97 | 98 | int **bidGraph; // matrix representation of conflicts 99 | 100 | private: 101 | // file functions 102 | void skipComments(); 103 | void fileRead(int &int_input); 104 | void fileRead(double &double_input); 105 | void fileRead(const char *label, int &int_input); 106 | signed int fileReadGood(int bidnum); 107 | 108 | bool isAllWhitespace(char *input, int len); 109 | void initialize(); 110 | bool removeSingletonDummyGoods(); 111 | 112 | // processing 113 | int deleteDominatedBids(int t, bool singleton_cleared); 114 | 115 | // variables 116 | int num_goods, num_dummy_items, num_bids; 117 | 118 | Bid **bid; 119 | FILE *fp; 120 | int num_killed; 121 | char buffer[1000]; 122 | int first_unchecked_bid, bid_array_size; 123 | bool delRemovedBids; 124 | map > goodMap; // -- map goods to bids 125 | }; 126 | 127 | #endif 128 | 129 | -------------------------------------------------------------------------------- /Distribution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "Distribution.h" 7 | #include "polyModel.h" 8 | 9 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) 10 | 11 | void Distribution::randomizeParamsWithDistribution(PolyModel *dist, int num_params, double *param_mins, double *param_maxs, double *params, Param &p) 12 | { 13 | if (dist->numVars != num_params) { 14 | printf("Error: parameter model has incorrect number of params for distribution.\n"); 15 | exit(1); 16 | } 17 | 18 | PolyModel normalizedDist(*dist); 19 | 20 | if (!p.no_normalization) { 21 | 22 | // adjust estimate to have minimum zero 23 | if (!dist->minimumKnown) { 24 | if (p.output_parameter_settings) { 25 | printf("Normalizing distribution from \"%s\"...\n", dist->filename); 26 | } 27 | dist->findMinimum(param_mins, param_maxs); 28 | } 29 | 30 | if (!dist->isConstant) { 31 | normalizedDist.add(-dist->minimum); 32 | } 33 | 34 | // integrate to get normalizing constant 35 | PolyModel copyForNorm(normalizedDist); 36 | for (int i = 0; i < copyForNorm.numVars; i++) { 37 | assert(param_mins[i] <= param_maxs[i]); 38 | if (param_mins[i] == param_maxs[i]) { 39 | copyForNorm.instantiate(i, param_mins[i]); 40 | } 41 | else { 42 | copyForNorm.integrateOut(i, param_mins[i], param_maxs[i]); 43 | } 44 | } 45 | 46 | double divideFactor = copyForNorm.constantTerm(); 47 | normalizedDist.multiplyBy(1.0 / divideFactor); 48 | } 49 | 50 | for (int i = 0; i < num_params; i++) { 51 | if (param_mins[i] == param_maxs[i]) { 52 | params[i] = param_mins[i]; 53 | normalizedDist.instantiate(i, param_mins[i]); 54 | continue; 55 | } 56 | 57 | PolyModel copy(normalizedDist); 58 | 59 | // integrate out non-instantiated vars other than this 60 | for (int j = i + 1; j < num_params; j++) { 61 | if (param_mins[j] == param_maxs[j]) { 62 | copy.instantiate(j, param_mins[j]); 63 | } 64 | else { 65 | copy.integrateOut(j, param_mins[j], param_maxs[j]); 66 | } 67 | } 68 | 69 | double integralBase = copy.indefIntegralAt(i, param_mins[i]); 70 | double integral = copy.indefIntegralAt(i, param_maxs[i]) - integralBase; 71 | 72 | double targetCDFval = Param::DRand(0, 1); 73 | double search_min = param_mins[i]; 74 | double search_max = param_maxs[i]; 75 | bool found = false; 76 | double guess; 77 | 78 | // find val for this var 79 | while (!found) { 80 | guess = (search_min + search_max) / 2; 81 | 82 | double integralAtGuess = copy.indefIntegralAt(i, guess) - integralBase; 83 | double cdfAtGuess = integralAtGuess / integral; 84 | 85 | if (cdfAtGuess > targetCDFval + 0.000001) { 86 | search_max = guess; 87 | } 88 | else if (cdfAtGuess < targetCDFval - 0.000001) { 89 | search_min = guess; 90 | } 91 | else { 92 | found = true; 93 | } 94 | } 95 | 96 | // instantiate that var with new val 97 | normalizedDist.instantiate(i, guess); 98 | params[i] = guess; 99 | } 100 | 101 | // what's left in normalizedDist after everything is 102 | // instantiated is pdf at these params 103 | assert(normalizedDist.numFreeVars == 0); 104 | probOfParams = normalizedDist.constantTerm(); 105 | } 106 | 107 | -------------------------------------------------------------------------------- /Distribution.h: -------------------------------------------------------------------------------- 1 | // Distribution.h: implementation of the Distribution abstract class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #ifdef WIN32 6 | #pragma warning (disable : 4786) 7 | #endif 8 | 9 | #ifndef DISTRIBUTION_H 10 | #define DISTRIBUTION_H 11 | 12 | #include "Param.h" 13 | 14 | class BidSet; 15 | 16 | class Distribution { 17 | public: 18 | Distribution() { 19 | probOfParams = 1.0; 20 | } 21 | 22 | // the main function to be overridden in subclasses 23 | virtual BidSet *generate(Param &p) = 0; 24 | virtual char *outputSettings(bool val) = 0; 25 | 26 | virtual ~Distribution() { 27 | } 28 | 29 | virtual void randomizeParams(Param &p) = 0; 30 | double probOfParams; 31 | 32 | protected: 33 | // given a polynomial-defined distribution dist, 34 | // and a normalized estimate dist_estimate 35 | // this procedure fills the array params with 36 | // parameter settings drawn from that distribution. 37 | 38 | // mins and maxs are the minimum and maximum possible 39 | // values of each param 40 | 41 | void randomizeParamsWithDistribution(PolyModel *dist, int num_params, 42 | double *param_mins, double *param_maxs, double *params, Param &p); 43 | }; 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /Legacy.h: -------------------------------------------------------------------------------- 1 | // Legacy.h: interface for the Legacy class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #ifdef WIN32 6 | #pragma warning (disable : 4786) 7 | #endif 8 | 9 | #ifndef _LEGACY_H_ 10 | #define _LEGACY_H_ 11 | 12 | #include "bid.h" 13 | #include "normal.h" 14 | #include "BidSet.h" 15 | #include "Param.h" 16 | #include "Distribution.h" 17 | 18 | class Legacy : public Distribution { 19 | public: 20 | char * outputSettings(bool tofile); 21 | Legacy(Param &p, char * argv[], int argc); 22 | virtual ~Legacy(); 23 | BidSet *generate(Param &p); 24 | static void usage(); 25 | void randomizeParams(Param &p); 26 | 27 | protected: 28 | double generatePrice(int n, const Param &p); 29 | int generateNumGoods(Param &p); 30 | Bid *generateBid(int goods_in_bid, int total_goods, double price); 31 | Normal *norm; 32 | // bool printed_usage; 33 | 34 | // distribution parameters 35 | enum goods_enum { 36 | BINOMIAL = 1, EXPONENTIAL, RANDOM, CONSTANT, DECAY, NORMAL_GOODS 37 | } num_goods_type; 38 | 39 | int const_goods; 40 | 41 | enum pricing_enum { 42 | FIXED_RANDOM = 1, LINEAR_RANDOM, NORMAL_PRICE, QUADRATIC 43 | } pricing_type; 44 | 45 | double binom_cutoff; 46 | double q; 47 | double mu_goods; 48 | double sigma_goods; 49 | double high_fixed; 50 | double low_fixed; 51 | double high_linearly; 52 | double low_linearly; 53 | double mu_price; 54 | double sigma_price; 55 | double alpha; 56 | char* output_buffer; 57 | }; 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # to add new objects, just put them in this list and run make depend 2 | 3 | OBJ = bid.o BidSet.o Distribution.o arbitrary.o Legacy.o main.o matching.o normal.o Param.o paths.o regions.o scheduling.o polyModel.o featureCalc.o 4 | 5 | 6 | ######################################################## 7 | # UNCOMMENT/EDIT THESE TO COMPILE WITH CPLEX LIBRARIES 8 | ######################################################## 9 | 10 | INCLUDE = -I/usr/local/ilog/cplex80/include/ilcplex/ -I/usr/local/ilog/cplex80/include/ 11 | LIB = -lnsl -pthread -lm -lcplex 12 | LIBDIRS = -L/usr/local/ilog/cplex80/lib/i86_linux2_glibc2.2_gcc3.0/static_pic_mt/ 13 | 14 | # NOTE: REMOVE -DLINUX IN NEXT 2 LINES FOR COMPILATION IN UNIX 15 | # ADD: -DWIN32 AND -D_WIN32 FOR COMPILATION IN WINDOWS 16 | RELEASEFLAGS = -O5 -DNDEBUG -DLINUX -DUSE_CPLEX 17 | DEBUGFLAGS = -Wall -DDEBUG -g -DLINUX -DUSE_CPLEX 18 | 19 | ######################################################## 20 | # UNCOMMENT/EDIT THESE TO COMPILE WITH LPSOLVE 21 | ######################################################## 22 | 23 | #INCLUDE = -Ilp_solve_4.0 24 | #LIB = -lm -llpk 25 | #LIBDIRS = -Llp_solve_4.0 26 | 27 | # NOTE: REMOVE -DLINUX IN NEXT 2 LINES FOR COMPILATION IN UNIX 28 | # ADD: -DWIN32 AND -D_WIN32 FOR COMPILATION IN WINDOWS 29 | #RELEASEFLAGS = -O5 -DNDEBUG -DLINUX 30 | #DEBUGFLAGS = -Wall -DDEBUG -g -DLINUX 31 | #LPMAKE = cd lp_solve_4.0; make; 32 | #LPCLEAN = cd lp_solve_4.0; make clean; 33 | 34 | ############################################################ 35 | release: 36 | cd obj; make all "OBJ = ${OBJ}" "CPPFLAGS = ${RELEASEFLAGS} ${INCLUDE}"; 37 | ${LPMAKE} 38 | make all "VPATH = obj" "FLAGS = -o cats ${RELEASEFLAGS}" 39 | 40 | debug: 41 | cd debugobj; make all "OBJ = ${OBJ}" "CPPFLAGS = ${DEBUGFLAGS} ${INCLUDE}"; 42 | ${LPMAKE} 43 | make all "VPATH = debugobj" "FLAGS = -o debugcats ${DEBUGFLAGS}" 44 | 45 | all : $(OBJ) 46 | g++ $^ ${FLAGS} ${LIBDIRS} $(LIB) 47 | 48 | .PHONY: clean depend again 49 | 50 | clean: 51 | ${LPCLEAN} 52 | rm *obj/*.o cats >& /dev/null; 53 | 54 | depend: 55 | makedepend -Y -fobj/Makefile *.cc *.cpp # >& /dev/null 56 | makedepend -Y -fdebugobj/Makefile *.cc *.cpp # >& /dev/null 57 | 58 | again: 59 | make clean; make depend; make 60 | # DO NOT DELETE 61 | -------------------------------------------------------------------------------- /Param.h: -------------------------------------------------------------------------------- 1 | // Param.h: interface for the Param class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #ifdef WIN32 6 | #pragma warning (disable : 4786) 7 | #endif 8 | 9 | #ifndef _PARAM_H_ 10 | #define _PARAM_H_ 11 | 12 | #include 13 | #include "polyModel.h" 14 | 15 | #ifndef _WIN32 16 | #ifndef stricmp 17 | #define stricmp strcasecmp 18 | #endif 19 | #endif 20 | 21 | class Param { 22 | 23 | public: 24 | static const char* CATS_VERSION_STRING; // = "2.2" 25 | static const int dist_count; 26 | static const char* dname[]; 27 | static const char *defaultModelFilenamesFile, *defaultDistDist, *uniformHybridDist; 28 | 29 | enum dist_type { 30 | ARBITRARY, ARBITRARY_NPV, ARBITRARY_UPV, MATCHING, PATHS, REGIONS, REGIONS_NPV, 31 | REGIONS_UPV, SCHEDULING, L1, L2, L3, L4, L5, L6, L7, L8, UNASSIGNED 32 | }; 33 | 34 | dist_type distribution; 35 | static double ERand(unsigned short x[3]); 36 | static int Round(double val); 37 | 38 | // functions 39 | void Seed(); 40 | static double DRand(); 41 | static long LRand(); 42 | static double DRand(double minval, double maxval); 43 | static long LRand(long minval, long maxval); 44 | 45 | Param(char** argv, int argc); 46 | virtual ~Param(); 47 | char *outputSettings(bool tofile); 48 | int output_frequency; 49 | bool *argRecognized; 50 | 51 | // general variables 52 | int num_runs; 53 | bool cplex_output; 54 | int random_seed, random_seed2; 55 | const char *filename; 56 | const char *cplex_filename; 57 | const char *feat_filename; 58 | bool calculating; 59 | bool converting; 60 | 61 | // if non-NULL, param_dist 62 | // gives an estimate to the true dist based on parameters 63 | 64 | // param_feat_polys define a distribution based on 65 | // min of feature polynomials 66 | 67 | int num_feat_polys; 68 | const char *model_filenames_file; 69 | const char *dist_dist_file; 70 | PolyModel **param_dists; 71 | PolyModel *feat_polys[10]; 72 | bool no_normalization; 73 | double *dist_weight; 74 | 75 | // const char *feature_norm_vect_file; 76 | double *feature_norm_means; 77 | double *feature_norm_devs; 78 | 79 | int numWeightedSamples; 80 | int num_bids; 81 | bool random_bids; 82 | int min_bids, max_bids; 83 | 84 | int num_goods; 85 | bool random_goods; 86 | int min_goods, max_goods; 87 | bool remove_dominated_bids; 88 | bool output_parameter_settings; 89 | bool integer_prices; 90 | bool parse_error; 91 | bool verbatim; 92 | bool random_parameters; 93 | int bid_alpha; // for rounding to integer 94 | 95 | private: 96 | char *output_settings_buffer; 97 | void parseModelFiles(); 98 | void parseDistDistFile(); 99 | void usage(); 100 | void paramDistUsage(); 101 | }; 102 | 103 | #endif 104 | 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Combinatorial Auction Test Suite (CATS)

2 | Version 2.2 3 | 4 | The Combinatorial Auction Test Suite is a generator of combinatorial auction instances for the testing of CA algorithms. It features five distributions of instances from realistic, economically motivated domains, as well as a collection of artificial distributions that have been used in the literature. Since the release of CATS 1.0 in 2000, it has become a standard benchmark for the evaluation and comparison of CA algorithms. 5 | 6 | See the full README and user guide here: https://www.cs.ubc.ca/~kevinlb/CATS/ 7 | -------------------------------------------------------------------------------- /arbitrary.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "Distribution.h" 7 | #include "regions.h" 8 | #include "arbitrary.h" 9 | 10 | // build the arbitrary adjacency map 11 | int Arbitrary::BuildMap() 12 | { 13 | int i, j; 14 | // numbids = 0; 15 | // numdummy = 0; 16 | 17 | for (i = 0; i < num_goods; i++) { 18 | if (location[i].d == NULL) { 19 | location[i].d = new double[num_goods]; 20 | } 21 | 22 | location[i].d[i] = 0; 23 | location[i].numneigh = 0; // NULL; // only used in the "regions" superclass 24 | location[i].neighbor = NULL; // only used in the "regions" superclass 25 | } 26 | 27 | for (i = 0; i < num_goods; i++) { 28 | for (j = i + 1; j < num_goods; j++) { 29 | do { 30 | location[i].d[j] = Param::DRand(); 31 | location[j].d[i] = location[i].d[j]; 32 | } 33 | while (!location[i].d[j]); // make sure nothing has zero probability 34 | } 35 | } 36 | 37 | return 0; 38 | } 39 | 40 | // decide how much weight to add if location a and b are in the same bid 41 | double Arbitrary::weightFromLocations(int a, int b) 42 | { 43 | return location[b].pn * location[b].d[a]; 44 | } 45 | 46 | // constructor 47 | Arbitrary::Arbitrary(Param &p, char * argv[], int argc) : Regions(p, argv, argc) 48 | { 49 | jump_prob = 0.0; // this is never supported under arbitrary, regardless of settings 50 | } 51 | 52 | // destructor 53 | Arbitrary::~Arbitrary() 54 | { 55 | // No special cleanup necessary: everything is taken care of in Regions 56 | } 57 | 58 | -------------------------------------------------------------------------------- /arbitrary.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARBITRARY_H 2 | #define _ARBITRARY_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "Distribution.h" 9 | #include "regions.h" 10 | 11 | class Arbitrary : public Regions { 12 | public: 13 | 14 | // constructor 15 | Arbitrary(Param &p, char * argv[], int argc); 16 | 17 | // destructor 18 | ~Arbitrary(); 19 | 20 | protected: 21 | 22 | // build the arbitrary adjacency map 23 | virtual int BuildMap(); 24 | 25 | // decide how much weight to add if location a and b are in the same bid 26 | virtual double weightFromLocations(int a, int b); 27 | 28 | }; 29 | 30 | #endif // _ARBITRARY_H 31 | 32 | -------------------------------------------------------------------------------- /bid.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////// 2 | /* Stores a full or partial Bid */ 3 | ////////////////////////////////// 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "bid.h" 10 | 11 | /* constructor */ 12 | Bid::Bid(double a, int i) 13 | { 14 | // vec = v; 15 | amount = a; 16 | array = new unsigned[array_size = 10]; 17 | num_goods = 0; // the number of goods belonging to this bid 18 | visited = false; 19 | sorted = false; 20 | indexInBidSet = i; 21 | conflicts = 0; 22 | } 23 | 24 | /* destructor */ 25 | 26 | Bid::~Bid() 27 | { 28 | delete[] array; 29 | } 30 | 31 | int Bid::firstDummyGood(unsigned total_goods) 32 | { 33 | for (int t = num_goods - 1; t >= 0; t--) { 34 | if (array[t] >= total_goods) { 35 | return array[t]; 36 | } 37 | } 38 | 39 | return -1; 40 | } 41 | 42 | void Bid::addGood(unsigned g) 43 | { 44 | if (num_goods == array_size) { 45 | unsigned *temp_array = new unsigned[array_size *= 2]; 46 | 47 | if (temp_array == 0) { 48 | fprintf(stderr, "Bid::addGood: Out of memory\n"); 49 | exit(1); 50 | } 51 | 52 | for (int t = 0; t < num_goods; t++) { 53 | temp_array[t] = array[t]; 54 | } 55 | 56 | delete[] array; 57 | array = temp_array; 58 | } 59 | 60 | // when not in debug mode, optimizer will remove this loop 61 | for (int i = 0; i < num_goods; i++) { 62 | assert(array[i] != g); 63 | } 64 | 65 | array[num_goods++] = g; 66 | sorted = false; 67 | } 68 | 69 | // log-time implementation on ordered bid list 70 | int Bid::indexOf(unsigned g) 71 | { 72 | if (!sorted) { 73 | sort(); 74 | } 75 | 76 | if (num_goods == 0) { 77 | return -1; 78 | } 79 | 80 | // jump is a power of two representing how far we will jump for the next try 81 | // it is initialized to the largest power of 2 that's <= num_goods 82 | int jump = 1; 83 | 84 | while (jump <= num_goods) { 85 | jump *= 2; 86 | } 87 | 88 | jump /= 2; 89 | int guess = jump - 1; 90 | 91 | while (array[guess] != g) { 92 | jump /= 2; 93 | 94 | if (jump == 0) { 95 | return -1; 96 | } 97 | 98 | if (array[guess] < g) { 99 | while (guess + jump >= num_goods) { 100 | jump /= 2; 101 | 102 | if (jump == 0) { 103 | return -1; 104 | } 105 | } 106 | 107 | guess += jump; 108 | } 109 | else { 110 | guess -= jump; 111 | } 112 | } 113 | 114 | return guess; 115 | } 116 | 117 | bool Bid::conflictsWith(Bid *other) 118 | { 119 | if (!sorted) { 120 | sort(); 121 | } 122 | 123 | if (!other->sorted) { 124 | other->sort(); 125 | } 126 | 127 | int myIt = 0, otherIt = 0; 128 | 129 | while (myIt < num_goods && otherIt < other->num_goods) { 130 | if (array[myIt] < other->array[otherIt]) { 131 | myIt++; 132 | } 133 | else if (array[myIt] > other->array[otherIt]) { 134 | otherIt++; 135 | } 136 | else { 137 | return true; 138 | } 139 | } 140 | 141 | return false; 142 | } 143 | 144 | bool Bid::subsetEqualOf(Bid *other) 145 | { 146 | // bid must not be longer 147 | if (num_goods > other->num_goods) { 148 | return false; 149 | } 150 | 151 | if (!sorted) { 152 | sort(); 153 | } 154 | 155 | if (!other->sorted) { 156 | other->sort(); 157 | } 158 | 159 | int myIt = 0, otherIt = 0; 160 | 161 | while (myIt < num_goods) { 162 | if (otherIt >= other->num_goods || array[myIt] < other->array[otherIt]) { 163 | return false; 164 | } 165 | else if (array[myIt] > other->array[otherIt]) { 166 | otherIt++; 167 | } 168 | else { 169 | myIt++; 170 | } 171 | } 172 | 173 | return true; 174 | } 175 | 176 | int Bid::largestGood() 177 | { 178 | if (sorted) { 179 | return array[num_goods - 1]; 180 | } 181 | else { 182 | int largest = -1; 183 | 184 | for (int i = 0; i < num_goods; i++) { 185 | if ((int) array[i] > largest) { 186 | largest = array[i]; 187 | } 188 | } 189 | 190 | return largest; 191 | } 192 | } 193 | 194 | void Bid::renumber(int *newNums) 195 | { 196 | for (int i = 0; i < num_goods; i++) { 197 | array[i] = newNums[array[i]]; 198 | } 199 | } 200 | 201 | void Bid::sort() 202 | { 203 | if (sorted) { 204 | return; 205 | } 206 | 207 | unsigned *tempArray = new unsigned[num_goods]; 208 | sortFrom(0, num_goods - 1, tempArray); 209 | delete[] tempArray; 210 | 211 | sorted = true; 212 | } 213 | 214 | void Bid::sortFrom(int begin, int end, unsigned *tempArray) 215 | { 216 | if (begin < end) { 217 | int middle = (begin + end) / 2; 218 | 219 | sortFrom(begin, middle, tempArray); 220 | sortFrom(middle + 1, end, tempArray); 221 | 222 | merge(begin, middle + 1, end, tempArray); 223 | } 224 | } 225 | 226 | void Bid::merge(int leftBegin, int rightBegin, int rightEnd, unsigned *tempArray) 227 | { 228 | int leftEnd = rightBegin - 1; 229 | int tempPos = leftBegin; 230 | int leftPos = leftBegin, rightPos = rightBegin; 231 | 232 | while (leftPos <= leftEnd && rightPos <= rightEnd) { 233 | if (array[leftPos] < array[rightPos]) { 234 | tempArray[tempPos++] = array[leftPos++]; 235 | } 236 | else { 237 | tempArray[tempPos++] = array[rightPos++]; 238 | } 239 | } 240 | 241 | while (leftPos <= leftEnd) { 242 | tempArray[tempPos++] = array[leftPos++]; 243 | } 244 | 245 | while (rightPos <= rightEnd) { 246 | tempArray[tempPos++] = array[rightPos++]; 247 | } 248 | 249 | for (int i = leftBegin; i <= rightEnd; i++) { 250 | array[i] = tempArray[i]; 251 | } 252 | } 253 | 254 | -------------------------------------------------------------------------------- /bid.h: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////// 2 | /* Stores a full or partial (bid) allocation */ 3 | /////////////////////////////////////////////// 4 | 5 | #ifdef WIN32 6 | #pragma warning (disable : 4786) 7 | #endif 8 | 9 | #ifndef BID_H 10 | #define BID_H 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | class Bid { 17 | public: 18 | 19 | Bid(double a, int i = 0); 20 | ~Bid(); 21 | double amount; 22 | int bid_num; 23 | int indexInBidSet; 24 | int num_goods; 25 | bool visited; 26 | 27 | //set conflicts; // -- Set of conflicting bids 28 | 29 | int conflicts; //Number of conflicts - o.w. runs out of memory 30 | int firstDummyGood(unsigned total_goods); 31 | void addGood(unsigned g); 32 | 33 | inline void removeGood(unsigned g) { 34 | if (num_goods > 0) { 35 | array[indexOf(g)] = array[--num_goods]; // it's OK if these are the same 36 | sorted = false; 37 | } 38 | } 39 | 40 | inline unsigned getGood(int index) { 41 | return array[index]; 42 | } 43 | 44 | inline bool contains(unsigned g) { 45 | return (indexOf(g) >= 0); 46 | } 47 | 48 | bool subsetEqualOf(Bid *other); 49 | bool conflictsWith(Bid *other); 50 | int largestGood(); 51 | void renumber(int *newNums); 52 | 53 | protected: 54 | unsigned *array; 55 | int array_size; 56 | int indexOf(unsigned g); 57 | void sort(); 58 | bool sorted; 59 | void sortFrom(int begin, int end, unsigned *tempArray); 60 | void merge(int leftBegin, int rightBegin, int rightEnd, unsigned *tempArray); 61 | }; 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /cats.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinlb1/CATS/38cbf35f5c36796522cb76895fd6388f0dd63f5c/cats.exe -------------------------------------------------------------------------------- /debugobj/Makefile: -------------------------------------------------------------------------------- 1 | VPATH = .. 2 | 3 | all : ${OBJ}# DO NOT DELETE 4 | # DO NOT DELETE 5 | 6 | testPoly.o: polyModel.h 7 | arbitrary.o: Distribution.h Param.h polyModel.h regions.h normal.h bid.h 8 | arbitrary.o: BidSet.h arbitrary.h 9 | bid.o: bid.h 10 | BidSet.o: BidSet.h bid.h Param.h polyModel.h Distribution.h 11 | Distribution.o: Distribution.h Param.h polyModel.h 12 | featureCalc.o: featureCalc.h BidSet.h bid.h Param.h polyModel.h 13 | featureCalc.o: Distribution.h 14 | Legacy.o: Legacy.h bid.h normal.h Param.h polyModel.h BidSet.h Distribution.h 15 | main.o: BidSet.h bid.h Param.h polyModel.h Distribution.h Legacy.h normal.h 16 | main.o: regions.h arbitrary.h scheduling.h matching.h paths.h featureCalc.h 17 | matching.o: bid.h BidSet.h Param.h polyModel.h Distribution.h matching.h 18 | normal.o: normal.h Param.h polyModel.h 19 | Param.o: Param.h polyModel.h Legacy.h bid.h normal.h BidSet.h Distribution.h 20 | Param.o: featureCalc.h 21 | paths.o: Param.h polyModel.h Distribution.h bid.h BidSet.h paths.h 22 | polyModel.o: polyModel.h Param.h 23 | regions.o: normal.h Param.h polyModel.h bid.h BidSet.h Distribution.h 24 | regions.o: regions.h 25 | scheduling.o: Distribution.h Param.h polyModel.h BidSet.h bid.h scheduling.h 26 | -------------------------------------------------------------------------------- /default_dist_dist: -------------------------------------------------------------------------------- 1 | 2113.1950925 2 | 2104.944155 3 | 0.038663 4 | 0 5 | 455.98677025 6 | 792.8073575 7 | 0.192181 8 | 0 9 | 3.070824 10 | 7504.87 11 | 1780.415 12 | 0 13 | 1.23826 14 | 1540.896 15 | 0 -------------------------------------------------------------------------------- /default_model_file: -------------------------------------------------------------------------------- 1 | -param_dist arbitrary-npv qpstuff/arbitrary-npv-qp.txt 2 | -param_dist arbitrary-upv qpstuff/arbitrary-upv-qp.txt 3 | -param_dist L2 qpstuff/L2-qp.txt 4 | -param_dist L3 qpstuff/L3-qp.txt 5 | -param_dist L4 qpstuff/L4-qp.txt 6 | -param_dist L6 qpstuff/L6-qp.txt 7 | -param_dist L7 qpstuff/L7-qp.txt 8 | -param_dist matching qpstuff/matching-qp.txt 9 | -param_dist regions-npv qpstuff/regions-npv-qp.txt 10 | -param_dist regions-upv qpstuff/regions-upv-qp.txt 11 | -param_dist scheduling qpstuff/scheduling-qp.txt 12 | -feat_poly qpstuff/cass-qp.txt 13 | -feat_poly qpstuff/cplex-qp.txt 14 | -feat_poly qpstuff/lehman-qp.txt 15 | -------------------------------------------------------------------------------- /featureCalc.h: -------------------------------------------------------------------------------- 1 | #ifndef _FEATURE_CALC_H 2 | #define _FEATURE_CALC_H 3 | 4 | #ifdef USE_CPLEX 5 | #include 6 | #else 7 | #include "lp_solve_4.0/lpkit.h" 8 | #include "lp_solve_4.0/patchlevel.h" 9 | #endif 10 | 11 | #include "BidSet.h" 12 | 13 | struct FeatureCalc { 14 | 15 | struct LPData { 16 | #ifdef USE_CPLEX 17 | CPXENVptr env; 18 | CPXLPptr lp; 19 | 20 | double *lb; 21 | double *ub; 22 | 23 | double *rhs; 24 | char *sense; 25 | 26 | int *rmatbeg; 27 | int *rmatind; 28 | double *rmatval; 29 | double *obj; 30 | #endif 31 | 32 | int status; 33 | double *xvals; 34 | 35 | LPData(); 36 | void deallocate(); 37 | void allocate(BidSet *b); 38 | 39 | } lpd; 40 | 41 | static const char *featureNames[]; 42 | static const int numFeatures = 32; 43 | double featureVals[numFeatures]; 44 | int featureNum; 45 | 46 | int num_bids; 47 | int num_goods; 48 | 49 | static const char *realistFeatureNames[]; 50 | static const int numRealismFeatures = 3; 51 | double realismFeatureVals[numFeatures]; 52 | int realismFeatureNum; 53 | 54 | void calcFeatures(BidSet &b); 55 | float testSmallWorldBidGraph(int bids, int **bidGraph, int calc); 56 | void LPfeatures(BidSet& bids); 57 | double LPsolve(BidSet *b); 58 | 59 | void writeFeatures(const char *filename); 60 | void writeFeatNames(const char *filename); 61 | }; 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /lp_solve_4.0/.cvsignore: -------------------------------------------------------------------------------- 1 | lex.c 2 | lp.c 3 | -------------------------------------------------------------------------------- /lp_solve_4.0/MANIFEST: -------------------------------------------------------------------------------- 1 | total 1620 2 | -rw-rw-rw- 1 peno group 32654 Jan 9 20:44 CHANGELOG 3 | -rw-rw-rw- 1 peno group 82600 Jan 16 2001 HARTMUT_DOCUMENTATION 4 | -rw-rw-rw- 1 peno group 26428 Jan 16 2001 LGPL.txt 5 | -rw-rw-rw- 1 peno group 26428 Jan 16 2001 LICENSE 6 | -rw-rw-rw- 1 peno group 0 Jan 9 21:58 MANIFEST 7 | -rw-rw-rw- 1 peno group 2899 Jan 16 2001 MIPLIB_RESULTS 8 | -rw-rw-rw- 1 peno group 4868 Jan 16 2001 MPS.description 9 | -rw-rw-rw- 1 peno group 3858 Jan 9 21:56 Makefile 10 | -rw-rw-rw- 1 peno group 3858 Nov 17 16:44 Makefile.linux 11 | -rw-rw-rw- 1 peno group 4134 Nov 17 16:18 Makefile.msc 12 | -rw-rw-rw- 1 peno group 3877 Nov 17 16:18 Makefile.sco5 13 | -rw-rw-rw- 1 peno group 3877 Nov 17 16:18 Makefile.unix 14 | -rw-rw-rw- 1 peno group 4576 Jan 16 2001 NETLIB_RESULTS 15 | -rw-rw-rw- 1 peno group 831 Nov 16 22:53 README 16 | -rw-rw-rw- 1 peno group 156740 Oct 5 21:22 SOSInterpolation.pdf 17 | -rw-rw-rw- 1 peno group 7125 Nov 16 18:27 debug.c 18 | -rw-rw-rw- 1 peno group 275 Dec 18 23:16 debug.h 19 | -rw-rw-rw- 1 peno group 389 Dec 18 23:15 declare.h 20 | -rw-rw-rw- 1 peno group 7823 Dec 24 14:55 demo.c 21 | -rw-rw-rw- 1 peno group 37516 Nov 16 17:57 fortify.c 22 | -rw-rw-rw- 1 peno group 4619 Nov 16 17:57 fortify.h 23 | -rw-rw-rw- 1 peno group 2769 Dec 22 14:32 hash.c 24 | -rw-rw-rw- 1 peno group 605 Dec 22 14:32 hash.h 25 | -rw-rw-rw- 1 peno group 1253 Sep 22 22:21 lex.l 26 | -rw-rw-rw- 1 peno group 4088 Sep 29 21:21 lp.y 27 | -rw-rw-rw- 1 peno group 1168 Nov 16 17:57 lp2mps.c 28 | drwxrwxrwx 2 peno group 1024 Jan 9 21:55 lp_examples 29 | -rw-rw-rw- 1 peno group 9419 Dec 15 01:21 lp_solve.1 30 | -rw-rw-rw- 1 peno group 10517 Dec 22 23:34 lp_solve.c 31 | -rw-rw-rw- 1 peno group 12969 Jan 9 21:45 lp_solve.man 32 | -rw-rw-rw- 1 peno group 842 Dec 18 23:14 lpglob.h 33 | -rw-rw-rw- 1 peno group 116281 Jan 9 20:32 lpkit.c 34 | -rw-rw-rw- 1 peno group 33588 Jan 9 21:38 lpkit.h 35 | -rw-rw-rw- 1 peno group 2535 Nov 16 16:12 lpsolve.rc 36 | -rw-rw-rw- 1 peno group 1150 Nov 16 17:57 mps2lp.c 37 | -rw-rw-rw- 1 peno group 163 Dec 24 16:54 patchlevel.h 38 | -rw-rw-rw- 1 peno group 10388 Jan 7 20:49 presolve.c 39 | -rw-rw-rw- 1 peno group 19337 Dec 22 19:49 read.c 40 | -rw-rw-rw- 1 peno group 344 Dec 18 23:13 read.h 41 | -rw-rw-rw- 1 peno group 23649 Nov 17 16:40 readmps.c 42 | -rw-rw-rw- 1 peno group 396 Aug 7 10:21 resource.h 43 | -rw-rw-rw- 1 peno group 89162 Dec 24 15:49 solve.c 44 | -rw-rw-rw- 1 peno group 1822 Dec 18 23:12 ufortify.h 45 | -rw-rw-rw- 1 peno group 30175 Jan 9 21:24 windll.c 46 | -rw-rw-rw- 1 peno group 4374 Jan 9 20:32 windll.def 47 | 48 | ./lp_examples: 49 | total 234 50 | -rw-rw-rw- 1 peno group 330 Nov 16 21:09 demo_lag.lp 51 | -rw-rw-rw- 1 peno group 378 Nov 17 16:15 demo_lag.out 52 | -rw-rw-rw- 1 peno group 65 Feb 25 2002 ex1.lp 53 | -rw-rw-rw- 1 peno group 192 Nov 17 22:11 ex1.out 54 | -rw-rw-rw- 1 peno group 14854 Nov 16 11:14 ex1sc.mps 55 | -rw-rw-rw- 1 peno group 4307 Nov 17 16:15 ex1sc.out 56 | -rw-rw-rw- 1 peno group 1023 Nov 16 11:30 ex1sos.mps 57 | -rw-rw-rw- 1 peno group 262 Nov 17 16:15 ex1sos.out 58 | -rw-rw-rw- 1 peno group 58 Jan 16 2001 ex2.lp 59 | -rw-rw-rw- 1 peno group 210 Nov 17 16:15 ex2.out 60 | -rw-rw-rw- 1 peno group 14854 Nov 16 11:15 ex2sc.mps 61 | -rw-rw-rw- 1 peno group 4311 Nov 17 16:15 ex2sc.out 62 | -rw-rw-rw- 1 peno group 1093 Nov 16 11:38 ex2sos.mps 63 | -rw-rw-rw- 1 peno group 273 Nov 17 16:15 ex2sos.out 64 | -rw-rw-rw- 1 peno group 55 Jan 16 2001 ex3.lp 65 | -rw-rw-rw- 1 peno group 201 Nov 17 16:15 ex3.out 66 | -rw-rw-rw- 1 peno group 1124 Nov 16 11:40 ex3sos.mps 67 | -rw-rw-rw- 1 peno group 289 Nov 17 16:15 ex3sos.out 68 | -rw-rw-rw- 1 peno group 4821 Jan 16 2001 ex4.lp 69 | -rw-rw-rw- 1 peno group 4320 Nov 17 16:15 ex4.out 70 | -rw-rw-rw- 1 peno group 1130 Nov 16 12:06 ex4sos.mps 71 | -rw-rw-rw- 1 peno group 289 Nov 17 16:15 ex4sos.out 72 | -rw-rw-rw- 1 peno group 8873 Jan 16 2001 ex5.lp 73 | -rw-rw-rw- 1 peno group 6152 Nov 17 16:15 ex5.out 74 | -rw-rw-rw- 1 peno group 6912 Nov 16 12:08 ex5sos.mps 75 | -rw-rw-rw- 1 peno group 1734 Nov 17 16:15 ex5sos.out 76 | -rw-rw-rw- 1 peno group 512 Jan 16 2001 ex6.lp 77 | -rw-rw-rw- 1 peno group 294 Nov 17 16:15 ex6.out 78 | -rw-rw-rw- 1 peno group 6912 Nov 16 12:11 ex6sos.mps 79 | -rw-rw-rw- 1 peno group 1739 Nov 17 16:15 ex6sos.out 80 | -rw-rw-rw- 1 peno group 7858 Jan 16 2001 ex7.lp 81 | -rw-rw-rw- 1 peno group 1325 Nov 17 16:15 ex7.out 82 | -------------------------------------------------------------------------------- /lp_solve_4.0/MIPLIB_RESULTS: -------------------------------------------------------------------------------- 1 | MILP problems from miplib sorted according to mps file size. Results 2 | obtained with lp_solve 2.0 on a 44 MFLOPS HP9000/735. 3 | 4 | lp_solve employs a rather simple branch-and-bound scheme to solve MILP 5 | problems and should not be expected to solve problems with a very large number 6 | (>100) of integer variables in reasonable time. 7 | 8 | Example, rows, cols, nonzero, integer and binary columns should be clear. 9 | 10 | OK result indicates that I have obtained the same result as indicated as 11 | correct. - indicates no result obtained. 12 | 13 | The remarks column indicates how a result was obtained, or why lp_solve failed. 14 | 15 | example rows cols nonzero integer binary result cpu time remarks 16 | (constr)(vars) vars vars 17 | ------------------------------------------------------------------------------- 18 | diamond 4 2 8 2 2 OK 0.0s 19 | stein9 13 9 45 9 9 OK 0.0s 20 | flugpl 18 18 46 11 0 OK 1.1s 21 | stein15 36 15 120 15 15 OK 0.3s 22 | p0033 16 33 98 33 33 OK 3.9s 23 | p0040 23 40 110 40 40 OK 0.1s 24 | sample2 45 67 146 21 21 OK 0.4s 25 | pipex 24 48 192 48 48 OK 5.4s 26 | mod013 62 96 192 48 48 OK 1.0s 27 | enigma 21 100 289 100 100 OK 27.3s 28 | bell5 91 104 266 58 30 OK 1h52m 29 | misc02 39 59 413 58 58 OK 0.1s 30 | egout 98 141 282 55 55 OK 1m48s 31 | lseu 28 89 309 89 89 OK 6m32s 32 | bell4 105 117 302 64 34 - > 20h 33 | bm23 20 27 478 27 27 OK 1.0s 34 | stein27 118 27 378 27 27 OK 36.7s 35 | bell3a 123 133 347 71 39 OK 44m52s 36 | bell3b 123 133 347 71 39 - > 14h 37 | rgn 24 180 460 100 100 OK 17.3s 38 | misc01 54 83 745 82 82 OK 2.3s 39 | noswot 182 128 735 100 75 - num. problems 40 | vpm1 234 378 749 168 168 - >1h30m 41 | stein45 331 45 1034 45 45 OK 54m48s 42 | modglob 291 422 968 98 98 - > 20h 43 | mod008 6 319 1243 319 319 - > 3h 44 | sentoy 30 60 1800 60 60 OK 1m00s 45 | misc03 96 160 2053 159 159 OK 10.9s 46 | p0201 133 201 1923 201 201 OK 3m14s 47 | set1ch 493 712 1412 240 240 - > 68h 48 | set1al 493 712 1412 240 240 - > 3h 49 | set1cl 493 712 1412 240 240 - > 3h 50 | p0282 241 282 1966 282 282 - > 16h 51 | p0291 252 291 2031 291 291 - > 23h 52 | p0548 176 548 1711 548 548 - > 3h 53 | misc05 300 136 2954 74 74 OK 1m13s 54 | gen 780 870 2592 150 144 OK 1h26m 55 | khb05250 101 1350 2700 24 24 OK 14m03s 56 | fixnet6 479 878 1756 378 378 - > 18h 57 | fixnet4 479 878 1756 378 378 - > 2h 58 | fixnet3 478 878 1756 378 378 - > 2h 59 | cracpb1 143 572 4158 572 572 - > 15h 60 | air01 23 771 771 771 OK 0.7s 61 | misc06 820 1808 5859 112 112 - num. problems 62 | lp4l 85 1086 4677 1086 1086 OK 39m10s 63 | misc07 212 260 8619 259 259 OK 17m52s 64 | dsbmip 1182 1886 7366 192 160 - num. problems 65 | l152lav 97 1989 9922 1989 1989 OK 21m38s 66 | p2756 755 2756 8937 2756 2756 - > 3h40m 67 | mod010 146 2655 11203 2655 2655 OK 24m34s 68 | misc04 1725 4897 17252 30 30 OK 2m39s 69 | mod011 4480 10958 22254 96 96 - num. problems 70 | rentacar 6803 9557 41868 55 55 - num. problems 71 | p6000 2176 6000 48249 6000 6000 - num. problems 72 | air05 426 7195 52121 7195 7195 - num. problems 73 | air02 50 6774 61555 6774 6774 OK 1m00s 74 | air06 825 8627 70806 8627 8627 - num. problems 75 | air04 823 8904 72965 8904 8904 - num. problems 76 | air03 124 10757 91028 10757 10757 OK 1m35s 77 | 78 | -------------------------------------------------------------------------------- /lp_solve_4.0/MPS.description: -------------------------------------------------------------------------------- 1 | (Stolen from ftp://softlib.cs.rice.edu/pub/miplib/mps_format) 2 | 3 | MPS input format was originally introduced by IBM to express linear 4 | and integer programs in a standard way. The format is a fixed column 5 | format, so care must be taken that all information is placed in the 6 | correct columns as described below. 7 | 8 | The following is not intended as a complete description of MPS format, 9 | but only as a brief introduction. For more information, the reader is 10 | directed to: 11 | 12 | "Advanced Linear Programming," by Bruce A. Murtagh 13 | "Computer Solutions of Linear Programs," by J.L. Nazareth 14 | 15 | 16 | It may be useful to look at an example MPS file while reading this 17 | MPS information. 18 | 19 | 20 | The following template is a guide for the use of MPS format: 21 | 22 | --------------------------------------------------------------------- 23 | Field: 1 2 3 4 5 6 24 | Columns: 2-3 5-12 15-22 25-36 40-47 50-61 25 | 26 | NAME problem name 27 | 28 | ROWS 29 | 30 | type name 31 | 32 | COLUMNS 33 | column row value row value 34 | name name name 35 | RHS 36 | rhs row value row value 37 | name name name 38 | RANGES 39 | range row value row value 40 | name name name 41 | BOUNDS 42 | 43 | type bound column value 44 | name name 45 | ENDATA 46 | --------------------------------------------------------------------- 47 | 48 | NOTES: 49 | 50 | A. In the ROWS section, each row of the constraint matrix must have a 51 | row type and a row name specified. The code for indicating row type 52 | is as follows: 53 | 54 | type meaning 55 | --------------------------- 56 | E equality 57 | L less than or equal 58 | G greater than or equal 59 | N objective 60 | N no restriction 61 | 62 | B. In the COLUMNS section, the names of the variables are defined along 63 | with the coefficients of the objective and all the nonzero constraint 64 | matrix elements. It is not necessary to specify columns for slack or 65 | surplus variables as this is taken care of automatically. 66 | 67 | C. The RHS section contains information for the right-hand side of the problem. 68 | 69 | D. The RANGES section is for constraints of the form: h <= constraint <= u . 70 | The range of the constraint is r = u - h . The value of r is specified 71 | in the RANGES section, and the value of u or h is specified in the RHS 72 | section. If b is the value entered in the RHS section, and r is the 73 | value entered in the RANGES section, then u and h are thus defined: 74 | 75 | row type sign of r h u 76 | ---------------------------------------------- 77 | G + or - b b + |r| 78 | L + or - b - |r| b 79 | E + b b + |r| 80 | E - b - |r| b 81 | 82 | 83 | E. In the BOUNDS section, bounds on the variables are specified. When 84 | bounds are not indicated, the default bounds ( 0 <= x < infinity ) 85 | are assumed. The code for indicating bound type is as follows: 86 | 87 | type meaning 88 | ----------------------------------- 89 | LO lower bound b <= x 90 | UP upper bound x <= b 91 | FX fixed variable x = b 92 | FR free variable 93 | MI lower bound -inf -inf < x 94 | BV binary variable x = 0 or 1 95 | LI lower bound (int) b <= x *1 96 | UI upper bound (int) x <= b *1 97 | 98 | *1 : BOUNDS type of LI / UI is AMPS syntax 99 | 100 | F. Sections RANGES and BOUNDS are optional as are the fields 5 and 6. 101 | Everything else is required. In regards to fields 5 and 6, consider 102 | the following 2 constraints: 103 | 104 | const1: 2x + 3y < 6 105 | const2: 5x + 8y < 20 106 | 107 | Two ways to enter the variable x in the COLUMNS section are: 108 | 109 | (Field: 2 3 4 5 6 ) 110 | 1. x const1 2.0 const2 5.0 111 | 112 | 2. x const1 2.0 113 | x const2 5.0 114 | 115 | G. A mixed integer program requires the specification of which variables 116 | are required to be integer. Markers are used to indicate the start 117 | and end of a group of integer variables. The start marker has its 118 | name in field 2, 'MARKER' in field 3, and 'INTORG' in field 5. The 119 | end marker has its name in field 2, 'MARKER' in field 3, and 'INTEND' 120 | in field 5. These markers are placed in the COLUMNS section. 121 | 122 | -------------------------------------------------------------------------------- /lp_solve_4.0/Makefile: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | 3 | #should be OK in most situations: 4 | #CFLAGS= -O 5 | 6 | # HP/UX 9.0X optimized code 7 | #CFLAGS= +O3 +Oaggressive +Olibcalls -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD 8 | # HP/UX 9.0X debugging 9 | #CFLAGS= -g -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD 10 | 11 | # nice for gcc 12 | CFLAGS= -O3 -Wall -pedantic -ansi 13 | #CFLAGS= -g -Wall -pedantic -ansi 14 | 15 | # Option -DCHECK checks for numerical problems during rounding of numbers. 16 | # It will slow things down a bit. 17 | # You can add a -DREAL= to the CFLAGS, to change the default float 18 | # type used in lp_solve (double) to float or 'long double'. However, type float 19 | # might be fast on your computer, but it is not accurate enough to solve even 20 | # moderately sized problems without running into numerical problems. 21 | # The use of long doubles does increase the numerical stability of lp_solve, 22 | # if your compiler actually implements them with more bits than a double. But 23 | # it slows down things quite a bit. 24 | 25 | # Choose your favorite or available version of lex and yacc 26 | 27 | #YACC= yacc -d 28 | #especially for linux: 29 | YACC= bison -y -d 30 | 31 | #LEX= lex 32 | #especially for linux: 33 | LEX= flex -l 34 | 35 | #LEXLIB= -ll 36 | #especially for linux: 37 | LEXLIB= -lfl 38 | 39 | #ANSI math lib 40 | #MATHLIB= -lM 41 | #non-ANSI math lib, should also work 42 | MATHLIB= -lm 43 | 44 | LPKSRC.c= lpkit.c solve.c debug.c read.c readmps.c hash.c presolve.c 45 | LEXFILE.l= lex.l 46 | YACCFILE.y= lp.y 47 | TESTFILES1= lp_examples/*.lp 48 | TESTFILES2= lp_examples/*.mps 49 | 50 | TARGET=lp_solve 51 | LPKLIB=liblpk.a 52 | 53 | LEXFILE.c= $(LEXFILE.l:.l=.c) 54 | YACCFILE.c= $(YACCFILE.y:.y=.c) 55 | YACCFILE.o= $(YACCFILE.y:.y=.o) 56 | CSOURCES=lpkit.c solve.c debug.c read.c readmps.c lp_solve.c demo.c hash.c presolve.c $(LEXFILE.c) $(YACCFILE.c) 57 | COBJ=$(CSOURCES:.c=.o) 58 | LPKSRC= $(LPKSRC.c) $(YACCFILE.c) 59 | LPKOBJ= $(LPKSRC:.c=.o) 60 | HEADERS=lpkit.h lpglob.h patchlevel.h debug.h read.h hash.h declare.h ufortify.h fortify.h 61 | 62 | all: demo $(TARGET) lp2mps mps2lp 63 | 64 | $(COBJ): $(HEADERS) 65 | 66 | demo: demo.o $(LPKLIB) 67 | $(CC) -o demo $(CFLAGS) demo.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 68 | 69 | lp2mps: lp2mps.o $(LPKLIB) 70 | $(CC) -o lp2mps $(CFLAGS) lp2mps.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 71 | 72 | mps2lp: mps2lp.o $(LPKLIB) 73 | $(CC) -o mps2lp $(CFLAGS) lp.o mps2lp.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 74 | 75 | $(TARGET): lp_solve.o $(LPKLIB) 76 | $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 77 | 78 | purify: lp_solve.o $(LPKLIB) 79 | purify $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 80 | 81 | quantify: lp_solve.o $(LPKLIB) 82 | quantify $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 83 | 84 | $(LPKLIB): $(LPKOBJ) 85 | ar rv $@ $(LPKOBJ) 86 | ranlib $(LPKLIB) 87 | 88 | $(YACCFILE.o): $(LEXFILE.c) 89 | 90 | $(LEXFILE.c): $(LEXFILE.l) 91 | $(LEX) $(LEXFILE.l) 92 | mv lex.yy.c $(LEXFILE.c) 93 | 94 | $(YACCFILE.c): $(YACCFILE.y) 95 | $(YACC) $(YACCFILE.y) 96 | mv y.tab.c $(YACCFILE.c) 97 | 98 | test: 99 | -for i in $(TESTFILES1); do\ 100 | ./$(TARGET) -p -s -S3 -time < $$i > xxx.tmp;\ 101 | if diff xxx.tmp lp_examples/`basename $$i .lp`.out > /dev/null; then\ 102 | echo "$$i gives the correct result";\ 103 | else\ 104 | echo "*** $$i gives different result, please check ***";\ 105 | fi;\ 106 | done;\ 107 | for i in $(TESTFILES2); do\ 108 | ./$(TARGET) -mps -p -s -S3 -time < $$i > xxx.tmp;\ 109 | if diff xxx.tmp lp_examples/`basename $$i .mps`.out > /dev/null; then\ 110 | echo "$$i gives the correct result";\ 111 | else\ 112 | echo "*** $$i gives different result, please check ***";\ 113 | fi;\ 114 | done;\ 115 | rm xxx.tmp 116 | 117 | mktest: 118 | -for i in $(TESTFILES1); do\ 119 | ./$(TARGET) -p -s -S3 -time < $$i > lp_examples/`basename $$i .lp`.out;\ 120 | done;\ 121 | for i in $(TESTFILES2); do\ 122 | ./$(TARGET) -mps -p -s -S3 -time < $$i > lp_examples/`basename $$i .mps`.out;\ 123 | done;\ 124 | 125 | $(TARGET).man: $(TARGET).1 126 | nroff -man $(TARGET).1 > $(TARGET).man 127 | 128 | MANIFEST: clean 129 | ls -lR > MANIFEST; ls -lR > MANIFEST 130 | 131 | clean: 132 | rm -f *.a *.o TAGS $(LEXFILE.c) $(YACCFILE.c) demo $(TARGET) lp2mps mps2lp .pure .softdebughist datafile 133 | 134 | distrib: $(TARGET).man MANIFEST 135 | cd ..; tar -czvf lp_solve_4.0.tar.gz lp_solve_4.0 136 | 137 | TAGS: 138 | etags *.[chyl] 139 | -------------------------------------------------------------------------------- /lp_solve_4.0/Makefile.linux: -------------------------------------------------------------------------------- 1 | CC= gcc 2 | 3 | #should be OK in most situations: 4 | #CFLAGS= -O 5 | 6 | # HP/UX 9.0X optimized code 7 | #CFLAGS= +O3 +Oaggressive +Olibcalls -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD 8 | # HP/UX 9.0X debugging 9 | #CFLAGS= -g -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD 10 | 11 | # nice for gcc 12 | CFLAGS= -O3 -Wall -pedantic -ansi 13 | #CFLAGS= -g -Wall -pedantic -ansi 14 | 15 | # Option -DCHECK checks for numerical problems during rounding of numbers. 16 | # It will slow things down a bit. 17 | # You can add a -DREAL= to the CFLAGS, to change the default float 18 | # type used in lp_solve (double) to float or 'long double'. However, type float 19 | # might be fast on your computer, but it is not accurate enough to solve even 20 | # moderately sized problems without running into numerical problems. 21 | # The use of long doubles does increase the numerical stability of lp_solve, 22 | # if your compiler actually implements them with more bits than a double. But 23 | # it slows down things quite a bit. 24 | 25 | # Choose your favorite or available version of lex and yacc 26 | 27 | #YACC= yacc 28 | #especially for linux: 29 | YACC= bison -y 30 | 31 | #LEX= lex 32 | #especially for linux: 33 | LEX= flex -l 34 | 35 | #LEXLIB= -ll 36 | #especially for linux: 37 | LEXLIB= -lfl 38 | 39 | #ANSI math lib 40 | #MATHLIB= -lM 41 | #non-ANSI math lib, should also work 42 | MATHLIB= -lm 43 | 44 | LPKSRC.c= lpkit.c solve.c debug.c read.c readmps.c hash.c presolve.c 45 | LEXFILE.l= lex.l 46 | YACCFILE.y= lp.y 47 | TESTFILES1= lp_examples/*.lp 48 | TESTFILES2= lp_examples/*.mps 49 | 50 | TARGET=lp_solve 51 | LPKLIB=liblpk.a 52 | 53 | LEXFILE.c= $(LEXFILE.l:.l=.c) 54 | YACCFILE.c= $(YACCFILE.y:.y=.c) 55 | YACCFILE.o= $(YACCFILE.y:.y=.o) 56 | CSOURCES=lpkit.c solve.c debug.c read.c readmps.c lp_solve.c demo.c hash.c presolve.c $(LEXFILE.c) $(YACCFILE.c) 57 | COBJ=$(CSOURCES:.c=.o) 58 | LPKSRC= $(LPKSRC.c) $(YACCFILE.c) 59 | LPKOBJ= $(LPKSRC:.c=.o) 60 | HEADERS=lpkit.h lpglob.h patchlevel.h debug.h read.h hash.h declare.h ufortify.h fortify.h 61 | 62 | all: demo $(TARGET) lp2mps mps2lp 63 | 64 | $(COBJ): $(HEADERS) 65 | 66 | demo: demo.o $(LPKLIB) 67 | $(CC) -o demo $(CFLAGS) demo.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 68 | 69 | lp2mps: lp2mps.o $(LPKLIB) 70 | $(CC) -o lp2mps $(CFLAGS) lp2mps.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 71 | 72 | mps2lp: mps2lp.o $(LPKLIB) 73 | $(CC) -o mps2lp $(CFLAGS) mps2lp.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 74 | 75 | $(TARGET): lp_solve.o $(LPKLIB) 76 | $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 77 | 78 | purify: lp_solve.o $(LPKLIB) 79 | purify $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 80 | 81 | quantify: lp_solve.o $(LPKLIB) 82 | quantify $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 83 | 84 | $(LPKLIB): $(LPKOBJ) 85 | ar rv $@ $(LPKOBJ) 86 | ranlib $(LPKLIB) 87 | 88 | $(YACCFILE.o): $(LEXFILE.c) 89 | 90 | $(LEXFILE.c): $(LEXFILE.l) 91 | $(LEX) $(LEXFILE.l) 92 | mv lex.yy.c $(LEXFILE.c) 93 | 94 | $(YACCFILE.c): $(YACCFILE.y) 95 | $(YACC) $(YACCFILE.y) 96 | mv y.tab.c $(YACCFILE.c) 97 | 98 | test: 99 | -for i in $(TESTFILES1); do\ 100 | ./$(TARGET) -p -s -S3 -time < $$i > xxx.tmp;\ 101 | if diff xxx.tmp lp_examples/`basename $$i .lp`.out > /dev/null; then\ 102 | echo "$$i gives the correct result";\ 103 | else\ 104 | echo "*** $$i gives different result, please check ***";\ 105 | fi;\ 106 | done;\ 107 | for i in $(TESTFILES2); do\ 108 | ./$(TARGET) -mps -p -s -S3 -time < $$i > xxx.tmp;\ 109 | if diff xxx.tmp lp_examples/`basename $$i .mps`.out > /dev/null; then\ 110 | echo "$$i gives the correct result";\ 111 | else\ 112 | echo "*** $$i gives different result, please check ***";\ 113 | fi;\ 114 | done;\ 115 | rm xxx.tmp 116 | 117 | mktest: 118 | -for i in $(TESTFILES1); do\ 119 | ./$(TARGET) -p -s -S3 -time < $$i > lp_examples/`basename $$i .lp`.out;\ 120 | done;\ 121 | for i in $(TESTFILES2); do\ 122 | ./$(TARGET) -mps -p -s -S3 -time < $$i > lp_examples/`basename $$i .mps`.out;\ 123 | done;\ 124 | 125 | $(TARGET).man: $(TARGET).1 126 | nroff -man $(TARGET).1 > $(TARGET).man 127 | 128 | MANIFEST: clean 129 | ls -lR > MANIFEST; ls -lR > MANIFEST 130 | 131 | clean: 132 | rm -f *.a *.o TAGS $(LEXFILE.c) $(YACCFILE.c) demo $(TARGET) lp2mps mps2lp .pure .softdebughist datafile 133 | 134 | distrib: $(TARGET).man MANIFEST 135 | cd ..; tar -czvf lp_solve_4.0.tar.gz lp_solve_4.0 136 | 137 | TAGS: 138 | etags *.[chyl] 139 | -------------------------------------------------------------------------------- /lp_solve_4.0/Makefile.msc: -------------------------------------------------------------------------------- 1 | # Makefile for Microsoft visual C++ (tested on version 5 & 6) 2 | # to be called with GMAKE 3 | 4 | CC= cl 5 | 6 | ifndef RTLIB 7 | RTLIB= /ML 8 | endif 9 | CFLAGS=$(RTLIB) /O2 /W3 /DWIN32 /D_WINDOWS 10 | 11 | # Option -DCHECK checks for numerical problems during rounding of numbers. 12 | # It will slow things down a bit. 13 | # You can add a -DREAL= to the CFLAGS, to change the default float 14 | # type used in lp_solve (double) to float or 'long double'. However, type float 15 | # might be fast on your computer, but it is not accurate enough to solve even 16 | # moderately sized problems without running into numerical problems. 17 | # The use of long doubles does increase the numerical stability of lp_solve, 18 | # if your compiler actually implements them with more bits than a double. But 19 | # it slows down things quite a bit. 20 | 21 | # Choose your favorite or available version of lex and yacc 22 | 23 | YACC= bison -y 24 | 25 | LEX= flex -l 26 | 27 | RC= rc 28 | 29 | LEXLIB= 30 | 31 | #ANSI math lib 32 | MATHLIB= 33 | 34 | LPKSRC.c= lpkit.c solve.c debug.c read.c readmps.c hash.c presolve.c 35 | LEXFILE.l= lex.l 36 | YACCFILE.y= lp.y 37 | TESTFILES1= lp_examples/*.lp 38 | TESTFILES2= lp_examples/*.mps 39 | 40 | TARGET=lp_solve 41 | LPKLIB=liblpk.lib 42 | 43 | LEXFILE.c= $(LEXFILE.l:.l=.c) 44 | YACCFILE.c= $(YACCFILE.y:.y=.c) 45 | YACCFILE.obj= $(YACCFILE.y:.y=.obj) 46 | CSOURCES=lpkit.c solve.c debug.c read.c readmps.c hash.c presolve.c $(YACCFILE.c) 47 | COBJ=$(CSOURCES:.c=.obj) 48 | LPKSRC= $(LPKSRC.c) $(YACCFILE.c) 49 | LPKOBJ= $(LPKSRC:.c=.obj) 50 | HEADERS=lpkit.h lpglob.h patchlevel.h debug.h read.h hash.h declare.h ufortify.h fortify.h 51 | 52 | all: clean1 lpk clean2 dll 53 | 54 | dll: 55 | @$(MAKE) "RTLIB=/MD" lpsolve.dll 56 | 57 | lpk: demo.exe $(TARGET).exe lp2mps.exe mps2lp.exe 58 | 59 | $(COBJ): $(HEADERS) $(CSOURCES) $(LEXFILE.c) 60 | $(CC) -c $(CFLAGS) $(CSOURCES) 61 | 62 | demo.exe: demo.c $(HEADERS) $(LPKLIB) 63 | $(CC) -o demo $(CFLAGS) demo.c $(LPKLIB) $(LEXLIB) $(MATHLIB) 64 | 65 | lp2mps.exe: lp2mps.c $(HEADERS) $(LPKLIB) 66 | $(CC) -o lp2mps $(CFLAGS) lp2mps.c $(LPKLIB) $(LEXLIB) $(MATHLIB) 67 | 68 | mps2lp.exe: mps2lp.c $(HEADERS) $(LPKLIB) 69 | $(CC) -o mps2lp $(CFLAGS) mps2lp.c $(LPKLIB) $(LEXLIB) $(MATHLIB) 70 | 71 | $(TARGET).exe: lp_solve.c $(HEADERS) $(LPKLIB) 72 | $(CC) -o $(TARGET).exe $(CFLAGS) lp_solve.c $(LPKLIB) $(LEXLIB) $(MATHLIB) 73 | 74 | lpsolve.res: lpsolve.rc resource.h 75 | $(RC) lpsolve.rc 76 | 77 | windll.obj: $(HEADERS) windll.c 78 | $(CC) -c windll.c $(CFLAGS) 79 | 80 | lpsolve.dll: windll.obj windll.def lpsolve.res $(COBJ) 81 | link /DLL windll.obj /DEF:windll.def $(COBJ) lpsolve.res /OUT:lpsolve.dll 82 | 83 | $(LPKLIB): $(LPKOBJ) 84 | link /LIB $(LPKOBJ) /OUT:$@ 85 | 86 | $(YACCFILE.obj): $(LEXFILE.c) 87 | 88 | $(LEXFILE.c): $(LEXFILE.l) 89 | $(LEX) -o$(LEXFILE.c) $(LEXFILE.l) 90 | 91 | $(YACCFILE.c): $(YACCFILE.y) 92 | $(YACC) -o$(YACCFILE.c) $(YACCFILE.y) 93 | 94 | purify: lp_solve.obj $(LPKLIB) 95 | purify $(CC) -o $(TARGET).exe $(CFLAGS) lp_solve.obj $(LPKLIB) $(LEXLIB) $(MATHLIB) 96 | 97 | quantify: lp_solve.obj $(LPKLIB) 98 | quantify $(CC) -o $(TARGET).exe $(CFLAGS) lp_solve.obj $(LPKLIB) $(LEXLIB) $(MATHLIB) 99 | 100 | test: 101 | -for i in $(TESTFILES1); do\ 102 | ./$(TARGET) -p -s -S3 -time < $$i > xxx.tmp;\ 103 | if diff xxx.tmp lp_examples/`basename $$i .lp`.out > /dev/null; then\ 104 | echo "$$i gives the correct result";\ 105 | else\ 106 | echo "*** $$i gives different result, please check ***";\ 107 | fi;\ 108 | done;\ 109 | for i in $(TESTFILES2); do\ 110 | ./$(TARGET) -mps -p -s -S3 -time < $$i > xxx.tmp;\ 111 | if diff xxx.tmp lp_examples/`basename $$i .mps`.out > /dev/null; then\ 112 | echo "$$i gives the correct result";\ 113 | else\ 114 | echo "*** $$i gives different result, please check ***";\ 115 | fi;\ 116 | done;\ 117 | rm xxx.tmp 118 | 119 | mktest: 120 | -for i in $(TESTFILES1); do\ 121 | ./$(TARGET) -p -s -S3 -time < $$i > lp_examples/`basename $$i .lp`.out;\ 122 | done;\ 123 | for i in $(TESTFILES2); do\ 124 | ./$(TARGET) -mps -p -s -S3 -time < $$i > lp_examples/`basename $$i .mps`.out;\ 125 | done;\ 126 | 127 | $(TARGET).man: $(TARGET).1 128 | nroff -man $(TARGET).1 > $(TARGET).man 129 | 130 | MANIFEST: clean 131 | ls -lR > MANIFEST; ls -lR > MANIFEST 132 | 133 | cleanobj: 134 | rm -f "*.obj" 135 | 136 | clean1: cleanobj 137 | 138 | clean2: 139 | rm -f "*.obj" 140 | 141 | clean: cleanobj 142 | rm -f $(LPKLIB) 143 | rm -f $(LEXFILE.c) $(YACCFILE.c) lpsolve.exp lpsolve.lib lpsolve.res pe.cfg lp_examples\pe.cfg demo.exe $(TARGET).exe lp2mps.exe mps2lp.exe lpsolve.dll 144 | 145 | distrib: $(TARGET).man MANIFEST 146 | cd ..; tar -cvf - lp_solve_4.0 | gzip --best > lp_solve_4.0.tar.gz 147 | 148 | TAGS: 149 | etags *.[chyl] 150 | -------------------------------------------------------------------------------- /lp_solve_4.0/Makefile.sco5: -------------------------------------------------------------------------------- 1 | CC= cc 2 | 3 | #should be OK in most situations: 4 | CFLAGS= -O -s 5 | 6 | # HP/UX 9.0X optimized code 7 | #CFLAGS= +O3 +Oaggressive +Olibcalls -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD 8 | # HP/UX 9.0X debugging 9 | #CFLAGS= -g -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD 10 | 11 | # nice for gcc 12 | #CFLAGS= -O3 -Wall -pedantic -ansi 13 | #CFLAGS= -g -Wall -pedantic -ansi 14 | 15 | # Option -DCHECK checks for numerical problems during rounding of numbers. 16 | # It will slow things down a bit. 17 | # You can add a -DREAL= to the CFLAGS, to change the default float 18 | # type used in lp_solve (double) to float or 'long double'. However, type float 19 | # might be fast on your computer, but it is not accurate enough to solve even 20 | # moderately sized problems without running into numerical problems. 21 | # The use of long doubles does increase the numerical stability of lp_solve, 22 | # if your compiler actually implements them with more bits than a double. But 23 | # it slows down things quite a bit. 24 | 25 | # Choose your favorite or available version of lex and yacc 26 | 27 | YACC= yacc 28 | #especially for linux: 29 | #YACC= bison -y 30 | 31 | LEX= lex 32 | #especially for linux: 33 | #LEX= flex -l 34 | 35 | LEXLIB= -ll 36 | #especially for linux: 37 | #LEXLIB= -lfl 38 | 39 | #ANSI math lib 40 | #MATHLIB= -lM 41 | #non-ANSI math lib, should also work 42 | MATHLIB= -lm 43 | 44 | LPKSRC.c= lpkit.c solve.c debug.c read.c readmps.c hash.c presolve.c 45 | LEXFILE.l= lex.l 46 | YACCFILE.y= lp.y 47 | TESTFILES1= lp_examples/*.lp 48 | TESTFILES2= lp_examples/*.mps 49 | 50 | TARGET=lp_solve 51 | LPKLIB=liblpk.a 52 | 53 | LEXFILE.c= $(LEXFILE.l:.l=.c) 54 | YACCFILE.c= $(YACCFILE.y:.y=.c) 55 | YACCFILE.o= $(YACCFILE.y:.y=.o) 56 | CSOURCES=lpkit.c solve.c debug.c read.c readmps.c lp_solve.c demo.c hash.c presolve.c $(LEXFILE.c) $(YACCFILE.c) 57 | COBJ=$(CSOURCES:.c=.o) 58 | LPKSRC= $(LPKSRC.c) $(YACCFILE.c) 59 | LPKOBJ= $(LPKSRC:.c=.o) 60 | HEADERS=lpkit.h lpglob.h patchlevel.h debug.h read.h hash.h declare.h ufortify.h fortify.h 61 | 62 | all: demo $(TARGET) lp2mps mps2lp 63 | 64 | $(COBJ): $(HEADERS) 65 | 66 | demo: demo.o $(LPKLIB) 67 | $(CC) -o demo $(CFLAGS) demo.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 68 | 69 | lp2mps: lp2mps.o $(LPKLIB) 70 | $(CC) -o lp2mps $(CFLAGS) lp2mps.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 71 | 72 | mps2lp: mps2lp.o $(LPKLIB) 73 | $(CC) -o mps2lp $(CFLAGS) mps2lp.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 74 | 75 | $(TARGET): lp_solve.o $(LPKLIB) 76 | $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 77 | 78 | purify: lp_solve.o $(LPKLIB) 79 | purify $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 80 | 81 | quantify: lp_solve.o $(LPKLIB) 82 | quantify $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 83 | 84 | $(LPKLIB): $(LPKOBJ) 85 | ar rv $@ $(LPKOBJ) 86 | ranlib $(LPKLIB) 87 | 88 | $(YACCFILE.o): $(LEXFILE.c) 89 | 90 | $(LEXFILE.c): $(LEXFILE.l) 91 | $(LEX) $(LEXFILE.l) 92 | mv lex.yy.c $(LEXFILE.c) 93 | 94 | $(YACCFILE.c): $(YACCFILE.y) 95 | $(YACC) $(YACCFILE.y) 96 | mv y.tab.c $(YACCFILE.c) 97 | 98 | test: 99 | -for i in $(TESTFILES1); do\ 100 | ./$(TARGET) -p -s -S3 -time < $$i > xxx.tmp;\ 101 | if diff xxx.tmp lp_examples/`basename $$i .lp`.out > /dev/null; then\ 102 | echo "$$i gives the correct result";\ 103 | else\ 104 | echo "*** $$i gives different result, please check ***";\ 105 | fi;\ 106 | done;\ 107 | for i in $(TESTFILES2); do\ 108 | ./$(TARGET) -mps -p -s -S3 -time < $$i > xxx.tmp;\ 109 | if diff xxx.tmp lp_examples/`basename $$i .mps`.out > /dev/null; then\ 110 | echo "$$i gives the correct result";\ 111 | else\ 112 | echo "*** $$i gives different result, please check ***";\ 113 | fi;\ 114 | done;\ 115 | rm xxx.tmp 116 | 117 | mktest: 118 | -for i in $(TESTFILES1); do\ 119 | ./$(TARGET) -p -s -S3 -time < $$i > lp_examples/`basename $$i .lp`.out;\ 120 | done;\ 121 | for i in $(TESTFILES2); do\ 122 | ./$(TARGET) -mps -p -s -S3 -time < $$i > lp_examples/`basename $$i .mps`.out;\ 123 | done;\ 124 | 125 | $(TARGET).man: $(TARGET).1 126 | nroff -man $(TARGET).1 > $(TARGET).man 127 | 128 | MANIFEST: clean 129 | ls -lR > MANIFEST; ls -lR > MANIFEST 130 | 131 | clean: 132 | rm -f *.a *.o TAGS $(LEXFILE.c) $(YACCFILE.c) demo $(TARGET) lp2mps mps2lp .pure .softdebughist datafile 133 | 134 | distrib: $(TARGET).man MANIFEST 135 | cd ..; tar -cvf - lp_solve_4.0 | gzip --best > lp_solve_4.0.tar.gz 136 | 137 | TAGS: 138 | etags *.[chyl] 139 | -------------------------------------------------------------------------------- /lp_solve_4.0/Makefile.unix: -------------------------------------------------------------------------------- 1 | CC= cc 2 | 3 | #should be OK in most situations: 4 | CFLAGS= -O -s 5 | 6 | # HP/UX 9.0X optimized code 7 | #CFLAGS= +O3 +Oaggressive +Olibcalls -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD 8 | # HP/UX 9.0X debugging 9 | #CFLAGS= -g -Aa -D_POSIX_SOURCE -DCHECK +FP VZOUiD 10 | 11 | # nice for gcc 12 | #CFLAGS= -O3 -Wall -pedantic -ansi 13 | #CFLAGS= -g -Wall -pedantic -ansi 14 | 15 | # Option -DCHECK checks for numerical problems during rounding of numbers. 16 | # It will slow things down a bit. 17 | # You can add a -DREAL= to the CFLAGS, to change the default float 18 | # type used in lp_solve (double) to float or 'long double'. However, type float 19 | # might be fast on your computer, but it is not accurate enough to solve even 20 | # moderately sized problems without running into numerical problems. 21 | # The use of long doubles does increase the numerical stability of lp_solve, 22 | # if your compiler actually implements them with more bits than a double. But 23 | # it slows down things quite a bit. 24 | 25 | # Choose your favorite or available version of lex and yacc 26 | 27 | YACC= yacc 28 | #especially for linux: 29 | #YACC= bison -y 30 | 31 | LEX= lex 32 | #especially for linux: 33 | #LEX= flex -l 34 | 35 | LEXLIB= -ll 36 | #especially for linux: 37 | #LEXLIB= -lfl 38 | 39 | #ANSI math lib 40 | #MATHLIB= -lM 41 | #non-ANSI math lib, should also work 42 | MATHLIB= -lm 43 | 44 | LPKSRC.c= lpkit.c solve.c debug.c read.c readmps.c hash.c presolve.c 45 | LEXFILE.l= lex.l 46 | YACCFILE.y= lp.y 47 | TESTFILES1= lp_examples/*.lp 48 | TESTFILES2= lp_examples/*.mps 49 | 50 | TARGET=lp_solve 51 | LPKLIB=liblpk.a 52 | 53 | LEXFILE.c= $(LEXFILE.l:.l=.c) 54 | YACCFILE.c= $(YACCFILE.y:.y=.c) 55 | YACCFILE.o= $(YACCFILE.y:.y=.o) 56 | CSOURCES=lpkit.c solve.c debug.c read.c readmps.c lp_solve.c demo.c hash.c presolve.c $(LEXFILE.c) $(YACCFILE.c) 57 | COBJ=$(CSOURCES:.c=.o) 58 | LPKSRC= $(LPKSRC.c) $(YACCFILE.c) 59 | LPKOBJ= $(LPKSRC:.c=.o) 60 | HEADERS=lpkit.h lpglob.h patchlevel.h debug.h read.h hash.h declare.h ufortify.h fortify.h 61 | 62 | all: demo $(TARGET) lp2mps mps2lp 63 | 64 | $(COBJ): $(HEADERS) 65 | 66 | demo: demo.o $(LPKLIB) 67 | $(CC) -o demo $(CFLAGS) demo.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 68 | 69 | lp2mps: lp2mps.o $(LPKLIB) 70 | $(CC) -o lp2mps $(CFLAGS) lp2mps.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 71 | 72 | mps2lp: mps2lp.o $(LPKLIB) 73 | $(CC) -o mps2lp $(CFLAGS) mps2lp.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 74 | 75 | $(TARGET): lp_solve.o $(LPKLIB) 76 | $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 77 | 78 | purify: lp_solve.o $(LPKLIB) 79 | purify $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 80 | 81 | quantify: lp_solve.o $(LPKLIB) 82 | quantify $(CC) -o $(TARGET) $(CFLAGS) lp_solve.o $(LPKLIB) $(LEXLIB) $(MATHLIB) 83 | 84 | $(LPKLIB): $(LPKOBJ) 85 | ar rv $@ $(LPKOBJ) 86 | ranlib $(LPKLIB) 87 | 88 | $(YACCFILE.o): $(LEXFILE.c) 89 | 90 | $(LEXFILE.c): $(LEXFILE.l) 91 | $(LEX) $(LEXFILE.l) 92 | mv lex.yy.c $(LEXFILE.c) 93 | 94 | $(YACCFILE.c): $(YACCFILE.y) 95 | $(YACC) $(YACCFILE.y) 96 | mv y.tab.c $(YACCFILE.c) 97 | 98 | test: 99 | -for i in $(TESTFILES1); do\ 100 | ./$(TARGET) -p -s -S3 -time < $$i > xxx.tmp;\ 101 | if diff xxx.tmp lp_examples/`basename $$i .lp`.out > /dev/null; then\ 102 | echo "$$i gives the correct result";\ 103 | else\ 104 | echo "*** $$i gives different result, please check ***";\ 105 | fi;\ 106 | done;\ 107 | for i in $(TESTFILES2); do\ 108 | ./$(TARGET) -mps -p -s -S3 -time < $$i > xxx.tmp;\ 109 | if diff xxx.tmp lp_examples/`basename $$i .mps`.out > /dev/null; then\ 110 | echo "$$i gives the correct result";\ 111 | else\ 112 | echo "*** $$i gives different result, please check ***";\ 113 | fi;\ 114 | done;\ 115 | rm xxx.tmp 116 | 117 | mktest: 118 | -for i in $(TESTFILES1); do\ 119 | ./$(TARGET) -p -s -S3 -time < $$i > lp_examples/`basename $$i .lp`.out;\ 120 | done;\ 121 | for i in $(TESTFILES2); do\ 122 | ./$(TARGET) -mps -p -s -S3 -time < $$i > lp_examples/`basename $$i .mps`.out;\ 123 | done;\ 124 | 125 | $(TARGET).man: $(TARGET).1 126 | nroff -man $(TARGET).1 > $(TARGET).man 127 | 128 | MANIFEST: clean 129 | ls -lR > MANIFEST; ls -lR > MANIFEST 130 | 131 | clean: 132 | rm -f *.a *.o TAGS $(LEXFILE.c) $(YACCFILE.c) demo $(TARGET) lp2mps mps2lp .pure .softdebughist datafile 133 | 134 | distrib: $(TARGET).man MANIFEST 135 | cd ..; tar -cvf - lp_solve_4.0 | gzip --best > lp_solve_4.0.tar.gz 136 | 137 | TAGS: 138 | etags *.[chyl] 139 | -------------------------------------------------------------------------------- /lp_solve_4.0/NETLIB_RESULTS: -------------------------------------------------------------------------------- 1 | Below are the results obtained with lp_solve version 2.1 on the netlib LP 2 | benchmark set. CPU times are on a HP9000 K260 (180 MHz PA RISC 8000 CPU) 3 | 4 | Please bear in mind that many of the netlib examples are considered difficult. 5 | There are commercial LP packages on the market that cannot solve them all. 6 | But, there are also packages that can. 7 | 8 | A dash in the CPU time column indicates lp_solve ran into (and detected) 9 | unrecoverable numerical trouble. 10 | 11 | PROBLEM SUMMARY TABLE 12 | 13 | Name Rows Cols Nonzeros CPU time (s) remarks 14 | ----------------------------------------------------------------------------- 15 | 25FV47 822 1571 11127 4057 long doubles 16 | 80BAU3B 2263 9799 29063 98.78 17 | ADLITTLE 57 97 465 0.02 18 | AFIRO 28 32 88 < 0.01 19 | AGG 489 163 2541 0.08 20 | AGG2 517 302 4515 0.11 21 | AGG3 517 302 4531 0.12 22 | BANDM 306 472 2659 0.74 23 | BEACONFD 174 262 3476 0.05 24 | BLEND 75 83 521 0.02 25 | BNL1 644 1175 6129 - 26 | BNL2 2325 3489 16124 2396 long doubles 27 | BOEING1 351 384 3865 0.63 28 | BOEING2 167 143 1339 0.06 29 | BORE3D 234 315 1525 0.17 30 | BRANDY 221 249 2150 0.5 31 | CAPRI 272 353 1786 0.18 32 | CYCLE 1904 2857 21322 45.83 33 | CZPROB 930 3523 14173 8.64 34 | D2Q06C 2172 5167 35674 - 35 | D6CUBE 416 6184 43888 36.84 36 | DEGEN2 445 534 4449 5.67 37 | DEGEN3 1504 1818 26230 252 38 | DFL001 6072 12230 41873 - 39 | E226 224 282 2767 0.33 40 | ETAMACRO 401 688 2489 0.59 41 | FFFFF800 525 854 6235 115 long doubles 42 | FINNIS 498 614 2714 0.62 43 | FIT1D 25 1026 14430 1.21 44 | FIT1P 628 1677 10894 13.27 45 | FIT2D 26 10500 138018 299 46 | FIT2P 3001 13525 60784 1302 47 | FORPLAN 162 421 4916 0.42 48 | GANGES 1310 1681 7021 4.52 49 | GFRD-PNC 617 1092 3467 0.70 50 | GREENBEA 2393 5405 31499 - 51 | GREENBEB 2393 5405 31499 - 52 | GROW15 301 645 5665 0.27 53 | GROW22 441 946 8318 0.60 54 | GROW7 141 301 2633 0.07 55 | ISRAEL 175 142 2358 0.08 56 | KB2 44 41 291 < 0.01 57 | LOTFI 154 308 1086 0.12 58 | MAROS 847 1443 10006 9.07 59 | MAROS-R7 3137 9408 151120 - 60 | MODSZK1 688 1620 4158 0.99 61 | NESM 663 2923 13988 - 62 | PEROLD 626 1376 6026 - 63 | PILOT 1442 3652 43220 - 64 | PILOT.JA 941 1988 14706 - 65 | PILOT.WE 723 2789 9218 - 66 | PILOT4 411 1000 5145 - 67 | PILOT87 2031 4883 73804 - 68 | PILOTNOV 976 2172 13129 - 69 | RECIPE 92 180 752 < 0.01 70 | SC105 106 103 281 0.03 71 | SC205 206 203 552 0.13 72 | SC50A 51 48 131 0.01 73 | SC50B 51 48 119 0.01 74 | SCAGR25 472 500 2029 0.97 75 | SCAGR7 130 140 553 0.04 76 | SCFXM1 331 457 2612 0.37 77 | SCFXM2 661 914 5229 1.6 78 | SCFXM3 991 1371 7846 3.97 79 | SCORPION 389 358 1708 0.28 80 | SCRS8 491 1169 4029 1.57 81 | SCSD1 78 760 3148 - 82 | SCSD6 148 1350 5666 - 83 | SCSD8 398 2750 11334 - 84 | SCTAP1 301 480 2052 0.22 85 | SCTAP2 1091 1880 8124 1.56 86 | SCTAP3 1481 2480 10734 3.05 87 | SEBA 516 1028 4874 0.39 88 | SHARE1B 118 225 1182 0.13 89 | SHARE2B 97 79 730 0.03 90 | SHELL 537 1775 4900 1.05 91 | SHIP04L 403 2118 8450 0.86 92 | SHIP04S 403 1458 5810 0.59 93 | SHIP08L 779 4283 17085 3.25 94 | SHIP08S 779 2387 9501 1.34 95 | SHIP12L 1152 5427 21597 6.30 96 | SHIP12S 1152 2763 10941 2.54 97 | SIERRA 1228 2036 9252 1.38 98 | STAIR 357 467 3857 1.75 99 | STANDATA 360 1075 3038 0.06 100 | STANDGUB 362 1184 3147 0.07 101 | STANDMPS 468 1075 3686 0.62 102 | STOCFOR1 118 111 474 0.02 103 | STOCFOR2 2158 2031 9492 11.05 104 | TUFF 334 587 4523 63.52 long doubles 105 | VTP.BASE 199 203 914 0.08 106 | WOOD1P 245 2594 70216 341 long doubles 107 | WOODW 1099 8405 37478 1294 long doubles 108 | 109 | Aborts: 17 110 | Solved correctly with doubles (64 bits): 70 111 | Solved correctly with long doubles (128 bits): 6 112 | 113 | -------------------------------------------------------------------------------- /lp_solve_4.0/README: -------------------------------------------------------------------------------- 1 | This is the lp_solve 4.0 release 2 | 3 | This lp_solve versions is released under the LGPL license. See LGPL.txt 4 | 5 | bug reports, succes stories and requests for changes are welcome at: 6 | 7 | Michel Berkelaar 8 | michel@ics.ele.tue.nl 9 | 10 | Most of the changes between 1.5 and 2.0 were contributed by: 11 | 12 | Jeroen Dirks 13 | jeroend@tor.numetrix.com 14 | 15 | Most of the changes between 3.2 and 4.0 were done by: 16 | Kjell Eikland 17 | Peter Notebaert 18 | 19 | The lastest version of lp_solve can always be found at: 20 | 21 | ftp://ftp.ics.ele.tue.nl/pub/lp_solve/ 22 | 23 | BUILDING LP_SOLVE 24 | 25 | Just edit the Makefile to pick the compiler, lex and yacc of your choice, and 26 | to set the desired compiler options. Then type 'make'. After a succesful make, 27 | type 'make test' to run a couple of examples and to test the results against 28 | the ones I got. Also run program 'demo' to test the procedural interface. 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /lp_solve_4.0/SOSInterpolation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinlb1/CATS/38cbf35f5c36796522cb76895fd6388f0dd63f5c/lp_solve_4.0/SOSInterpolation.pdf -------------------------------------------------------------------------------- /lp_solve_4.0/debug.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "lpkit.h" 4 | #include "lpglob.h" 5 | 6 | static FILE *stream = NULL; 7 | 8 | static void InitStream() { 9 | if (stream == NULL) 10 | stream = stdout; 11 | } 12 | 13 | int report(lprec *lp, short level, char *format, ...) { 14 | va_list ap; 15 | 16 | va_start(ap, format); 17 | if ((lp == NULL) || (lp->writelog == NULL)) { 18 | if ((lp == NULL) || (lp->verbose >= level)) { 19 | vfprintf(stderr, format, ap); 20 | fputc('\n', stderr); 21 | if (level == CRITICALSTOP) 22 | raise(SIGABRT); 23 | } 24 | } else if (lp->writelog != NULL) { 25 | if (lp->verbose >= level) { 26 | char buff[255]; 27 | 28 | vsprintf(buff, format, ap); 29 | lp->writelog(lp, lp->loghandle, buff); 30 | } 31 | } 32 | va_end(ap); 33 | 34 | return (0); 35 | } 36 | 37 | static void print_indent(lprec *lp) { 38 | int i; 39 | 40 | InitStream(); 41 | 42 | fprintf(stream, "%2d", lp->Level); 43 | if (lp->Level < 50) /* useless otherwise */ 44 | for (i = lp->Level; i > 0; i--) 45 | fprintf(stream, "--"); 46 | else 47 | fprintf(stream, " *** too deep ***"); 48 | fprintf(stream, "> "); 49 | } /* print_indent */ 50 | 51 | void debug_print_solution(lprec *lp) { 52 | int i; 53 | 54 | if (lp->debug) { 55 | InitStream(); 56 | 57 | for (i = lp->rows + 1; i <= lp->sum; i++) { 58 | print_indent(lp); 59 | fprintf(stream, "%-20s %g\n", get_col_name(lp, i - lp->rows), 60 | (double) lp->solution[i]); 61 | } 62 | } 63 | } /* debug_print_solution */ 64 | 65 | void debug_print_bounds(lprec *lp, REAL *upbo, REAL *lowbo) { 66 | int i; 67 | 68 | if (lp->debug) { 69 | InitStream(); 70 | 71 | for (i = lp->rows + 1; i <= lp->sum; i++) { 72 | if (lowbo[i] == upbo[i]) { 73 | print_indent(lp); 74 | fprintf(stream, "%s = %g\n", get_col_name(lp, i - lp->rows), 75 | (double) lowbo[i] * ((lp->scaling_used) ? lp->scale[i] : 1.0)); 76 | } else { 77 | if (lowbo[i] != 0) { 78 | print_indent(lp); 79 | fprintf(stream, "%s > %g\n", get_col_name(lp, i - lp->rows), 80 | (double) lowbo[i] * ((lp->scaling_used) ? lp->scale[i] : 1.0)); 81 | } 82 | if (upbo[i] != lp->infinite) { 83 | print_indent(lp); 84 | fprintf(stream, "%s < %g\n", get_col_name(lp, i - lp->rows), 85 | (double) upbo[i] * ((lp->scaling_used) ? lp->scale[i] : 1.0)); 86 | } 87 | } 88 | } 89 | } 90 | } /* debug_print_bounds */ 91 | 92 | void debug_print(lprec *lp, char *format, ...) { 93 | va_list ap; 94 | 95 | if (lp->debug) { 96 | InitStream(); 97 | 98 | print_indent(lp); 99 | va_start(ap, format); 100 | vfprintf(stream, format, ap); 101 | fputc('\n', stream); 102 | va_end(ap); 103 | } 104 | } /* debug_print */ 105 | 106 | void print_str(char *str) { 107 | InitStream(); 108 | 109 | fputs(str, stream); 110 | } 111 | 112 | void print_lp(lprec *lp) { 113 | int i, j; 114 | REAL *fatmat; 115 | 116 | InitStream(); 117 | 118 | if (CALLOC(fatmat, (lp->rows + 1) * lp->columns) != NULL) { 119 | for (i = 1; i <= lp->columns; i++) 120 | for (j = lp->col_end[i - 1]; j < lp->col_end[i]; j++) 121 | fatmat[(i - 1) * (lp->rows + 1) + lp->mat[j].row_nr] = lp->mat[j].value; 122 | 123 | fprintf(stream, "\nModel name: %s\n", lp->lp_name); 124 | fprintf(stream, " "); 125 | for (j = 1; j <= lp->columns; j++) 126 | fprintf(stream, "%8.8s ", get_col_name(lp, j)); 127 | if (lp->maximise) { 128 | fprintf(stream, "\nMaximize "); 129 | for (j = 0; j < lp->columns; j++) 130 | fprintf(stream, "%8g ", (double) -fatmat[j * (lp->rows + 1)]); 131 | } else { 132 | fprintf(stream, "\nMinimize "); 133 | for (j = 0; j < lp->columns; j++) 134 | fprintf(stream, "%8g ", (double) fatmat[j * (lp->rows + 1)]); 135 | } 136 | fprintf(stream, "\n"); 137 | for (i = 1; i <= lp->rows; i++) { 138 | fprintf(stream, "%-9s ", get_row_name(lp, i)); 139 | for (j = 0; j < lp->columns; j++) 140 | if (lp->ch_sign[i] && fatmat[j * (lp->rows + 1) + i] != 0) 141 | fprintf(stream, "%8g ", (double) -fatmat[j * (lp->rows + 1) + i]); 142 | else 143 | fprintf(stream, "%8g ", (double) fatmat[j * (lp->rows + 1) + i]); 144 | if (lp->orig_upbo[i] != 0) { 145 | if (lp->ch_sign[i]) 146 | fprintf(stream, ">= "); 147 | else 148 | fprintf(stream, "<= "); 149 | } else 150 | fprintf(stream, " = "); 151 | if (lp->ch_sign[i]) 152 | fprintf(stream, "%8g", (double) -lp->orig_rh[i]); 153 | else 154 | fprintf(stream, "%8g", (double) lp->orig_rh[i]); 155 | if (lp->orig_lowbo[i] != 0) { 156 | fprintf(stream, " %s = %8g", (lp->ch_sign[i]) ? "lowbo" : "upbo", 157 | (double) (lp->orig_lowbo[i] + lp->orig_rh[i])*(lp->ch_sign[i] ? 1.0 : -1.0)); 158 | } 159 | if ((lp->orig_upbo[i] != lp->infinite) && (lp->orig_upbo[i] != 0.0)) { 160 | fprintf(stream, " %s = %8g", (lp->ch_sign[i]) ? "upbo" : "lowbo", 161 | (double) (lp->orig_upbo[i] - lp->orig_rh[i])*(lp->ch_sign[i] ? 1.0 : -1.0)); 162 | } 163 | fprintf(stream, "\n"); 164 | } 165 | for (i = 0; i < lp->nr_lagrange; i++) { 166 | fprintf(stream, "lag[%-5d]", i); 167 | for (j = 1; j <= lp->columns; j++) 168 | fprintf(stream, "%8g ", (double) lp->lag_row[i][j]); 169 | if (lp->orig_upbo[i] == lp->infinite) { 170 | if (lp->lag_con_type[i] == GE) 171 | fprintf(stream, ">= "); 172 | else if (lp->lag_con_type[i] == LE) 173 | fprintf(stream, "<= "); 174 | else if (lp->lag_con_type[i] == EQ) 175 | fprintf(stream, " = "); 176 | } 177 | fprintf(stream, "%8g\n", (double) lp->lag_rhs[i]); 178 | } 179 | 180 | fprintf(stream, "Type "); 181 | for (i = 1; i <= lp->columns; i++) 182 | if (is_int(lp, i)) 183 | fprintf(stream, " Int "); 184 | else 185 | fprintf(stream, " Real "); 186 | fprintf(stream, "\nupbo "); 187 | for (i = 1; i <= lp->columns; i++) 188 | if (lp->orig_upbo[lp->rows + i] == lp->infinite) 189 | fprintf(stream, " Infinite"); 190 | else 191 | fprintf(stream, "%8g ", (double) lp->orig_upbo[lp->rows + i]); 192 | fprintf(stream, "\nlowbo "); 193 | for (i = 1; i <= lp->columns; i++) 194 | fprintf(stream, "%8g ", (double) lp->orig_lowbo[lp->rows + i]); 195 | fprintf(stream, "\n"); 196 | 197 | free(fatmat); 198 | } 199 | 200 | fflush(stream); 201 | } 202 | 203 | void print_objective(lprec *lp) { 204 | InitStream(); 205 | 206 | fprintf(stream, "\nValue of objective function: %g\n", 207 | (double) lp->best_solution[0]); 208 | } 209 | 210 | void print_solution(lprec *lp) { 211 | int i; 212 | 213 | InitStream(); 214 | 215 | fprintf(stream, "\nActual values of the variables:\n"); 216 | /* print normal variables */ 217 | for (i = 1; i <= lp->columns; i++) 218 | fprintf(stream, "%-20s %g\n", get_col_name(lp, i), 219 | (double) lp->best_solution[lp->rows + i]); 220 | 221 | fflush(stream); 222 | } /* Print_solution */ 223 | 224 | void print_constraints(lprec *lp) { 225 | int i; 226 | 227 | InitStream(); 228 | 229 | fprintf(stream, "\nActual values of the constraints:\n"); 230 | for (i = 1; i <= lp->rows; i++) 231 | fprintf(stream, "%-20s %g\n", get_row_name(lp, i), 232 | (double) lp->best_solution[i]); 233 | 234 | fflush(stream); 235 | } 236 | 237 | void print_duals(lprec *lp) { 238 | int i; 239 | 240 | InitStream(); 241 | 242 | fprintf(stream, "\nDual values with from - till limits:\n"); 243 | for (i = 1; i <= lp->rows + lp->columns; i++) 244 | fprintf(stream, "%-20s %8g %8g %8g\n", (i <= lp->rows) ? get_row_name(lp, i) : get_col_name(lp, i - lp->rows), 245 | (double) lp->duals[i], (double) lp->dualsfrom[i], (double) lp->dualstill[i]); 246 | fflush(stream); 247 | } 248 | 249 | void print_scales(lprec *lp) { 250 | int i; 251 | 252 | InitStream(); 253 | 254 | if (lp->scaling_used) { 255 | fprintf(stream, "\nScale factors:\n"); 256 | for (i = 0; i <= lp->rows + lp->columns; i++) 257 | fprintf(stream, "%-20s scaled at %g\n", (i <= lp->rows) ? get_row_name(lp, i) : get_col_name(lp, i - lp->rows), 258 | (double) lp->scale[i]); 259 | } 260 | fflush(stream); 261 | } 262 | 263 | int print_file(char *filename) { 264 | if ((stream != NULL) && (stream != stderr)) 265 | fclose(stream); 266 | 267 | if (filename == NULL) 268 | stream = stderr; 269 | else 270 | stream = fopen(filename, "w"); 271 | return (stream != NULL); 272 | } 273 | -------------------------------------------------------------------------------- /lp_solve_4.0/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEBUG_H__ 2 | #define __DEBUG_H__ 3 | 4 | /* prototypes for debug printing by other files */ 5 | 6 | void print_str(char *str); 7 | void debug_print(lprec *lp, char *format, ...); 8 | void debug_print_solution(lprec *lp); 9 | void debug_print_bounds(lprec *lp, REAL *upbo, REAL *lowbo); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /lp_solve_4.0/declare.h: -------------------------------------------------------------------------------- 1 | #ifndef __DECLARE_H__ 2 | #define __DECLARE_H__ 3 | 4 | #if !defined ANSI_PROTOTYPES 5 | #if defined MSDOS || defined __BORLANDC__ || defined __HIGHC__ || defined SCO_UNIX || defined AViiON 6 | #define ANSI_PROTOTYPES 1 7 | #endif 8 | #endif 9 | 10 | #if ANSI_PROTOTYPES!=0 11 | #define __OF(args) args 12 | #else 13 | #define __OF(args) () 14 | #endif 15 | 16 | #if defined __HIGHC__ 17 | #define VARARG ... 18 | #else 19 | #define VARARG 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /lp_solve_4.0/demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | This program is originally made by by Jeroen J. Dirks (jeroend@tor.numetrix.com) 3 | Adapted by Peter Notebaert (peno@mailme.org) 4 | */ 5 | 6 | #include 7 | 8 | #include "lpkit.h" 9 | #include "patchlevel.h" 10 | 11 | void press_ret(void) { 12 | printf("[return]"); 13 | getchar(); 14 | } 15 | 16 | int main(void) { 17 | #define ERROR() { fprintf(stderr, "Error\n"); exit(1); } 18 | lprec *lp1, *lp2; 19 | FILE *input_file; 20 | 21 | printf("lp_solve %d.%d.%d.%d demo\n\n", MAJORVERSION, MINORVERSION, RELEASE, BUILD); 22 | printf("This demo will show most of the features of lp_solve %d.%d.%d.%d\n", MAJORVERSION, MINORVERSION, RELEASE, BUILD); 23 | press_ret(); 24 | printf("\nWe start by creating a new problem with 4 variables and 0 constraints\n"); 25 | printf("We use: lp1=make_lp(0,4);\n"); 26 | if ((lp1 = make_lp(0, 4)) == NULL) 27 | ERROR(); 28 | press_ret(); 29 | printf("We can show the current problem with print_lp(lp1)\n"); 30 | print_lp(lp1); 31 | press_ret(); 32 | printf("Now we add some constraints\n"); 33 | printf("str_add_constraint(lp1, \"3 2 2 1\" ,LE,4)\n"); 34 | printf("This is the string version of add_constraint. For the normal version\n"); 35 | printf("of add_constraint see the file lpkit.h\n"); 36 | if (!str_add_constraint(lp1, "3 2 2 1", LE, 4)) 37 | ERROR(); 38 | print_lp(lp1); 39 | press_ret(); 40 | printf("str_add_constraint(lp1, \"0 4 3 1\" ,GE,3)\n"); 41 | if (!str_add_constraint(lp1, "0 4 3 1", GE, 3)) 42 | ERROR(); 43 | print_lp(lp1); 44 | press_ret(); 45 | printf("Set the objective function\n"); 46 | printf("str_set_obj_fn(lp1, \"2 3 -2 3\")\n"); 47 | if (!str_set_obj_fn(lp1, "2 3 -2 3")) 48 | ERROR(); 49 | print_lp(lp1); 50 | press_ret(); 51 | printf("Now solve the problem with printf(solve(lp1));\n"); 52 | printf("%d", solve(lp1)); 53 | press_ret(); 54 | printf("The value is 0, this means we found an optimal solution\n"); 55 | printf("We can display this solution with print_objective(lp1) and print_solution(lp1)\n"); 56 | print_objective(lp1); 57 | print_solution(lp1); 58 | press_ret(); 59 | printf("The dual variables of the solution are printed with\n"); 60 | printf("print_duals(lp1);\n"); 61 | print_duals(lp1); 62 | press_ret(); 63 | printf("We can change a single element in the matrix with\n"); 64 | printf("set_mat(lp1,2,1,0.5)\n"); 65 | if (!set_mat(lp1, 2, 1, 0.5)) 66 | ERROR(); 67 | print_lp(lp1); 68 | press_ret(); 69 | printf("If we want to maximize the objective function use set_maxim(lp1);\n"); 70 | set_maxim(lp1); 71 | print_lp(lp1); 72 | press_ret(); 73 | printf("after solving this gives us:\n"); 74 | solve(lp1); 75 | print_objective(lp1); 76 | print_solution(lp1); 77 | print_duals(lp1); 78 | press_ret(); 79 | printf("Change the value of a rhs element with set_rh(lp1,1,7.45)\n"); 80 | set_rh(lp1, 1, 7.45); 81 | print_lp(lp1); 82 | solve(lp1); 83 | print_objective(lp1); 84 | print_solution(lp1); 85 | press_ret(); 86 | printf("We change %s to the integer type with\n", get_row_name(lp1, 4)); 87 | printf("set_int(lp1, 4, TRUE)\n"); 88 | set_int(lp1, 4, TRUE); 89 | print_lp(lp1); 90 | printf("We set branch & bound debugging on with set_debug(lp1, TRUE)\n"); 91 | set_debug(lp1, TRUE); 92 | printf("and solve...\n"); 93 | press_ret(); 94 | solve(lp1); 95 | print_objective(lp1); 96 | print_solution(lp1); 97 | press_ret(); 98 | printf("We can set bounds on the variables with\n"); 99 | printf("set_lowbo(lp1,2,2); & set_upbo(lp1,4,5.3)\n"); 100 | set_lowbo(lp1, 2, 2); 101 | set_upbo(lp1, 4, 5.3); 102 | print_lp(lp1); 103 | press_ret(); 104 | solve(lp1); 105 | print_objective(lp1); 106 | print_solution(lp1); 107 | press_ret(); 108 | printf("Now remove a constraint with del_constraint(lp1, 1)\n"); 109 | del_constraint(lp1, 1); 110 | print_lp(lp1); 111 | printf("Add an equality constraint\n"); 112 | if (!str_add_constraint(lp1, "1 2 1 4", EQ, 8)) 113 | ERROR(); 114 | print_lp(lp1); 115 | press_ret(); 116 | printf("A column can be added with:\n"); 117 | printf("str_add_column(lp1,\"3 2 2\");\n"); 118 | if (!str_add_column(lp1, "3 2 2")) 119 | ERROR(); 120 | print_lp(lp1); 121 | press_ret(); 122 | printf("A column can be removed with:\n"); 123 | printf("del_column(lp1,3);\n"); 124 | del_column(lp1, 3); 125 | print_lp(lp1); 126 | press_ret(); 127 | printf("We can use automatic scaling with:\n"); 128 | printf("auto_scale(lp1);\n"); 129 | auto_scale(lp1); 130 | print_lp(lp1); 131 | press_ret(); 132 | printf("The function mat_elm(lprec *lp, int row, int column) returns a single\n"); 133 | printf("matrix element\n"); 134 | printf("%s mat_elm(lp1,2,3), mat_elm(lp1,1,1); gives\n", "printf(\"%f %f\\n\","); 135 | printf("%f %f\n", (double) mat_elm(lp1, 2, 3), (double) mat_elm(lp1, 1, 1)); 136 | printf("Notice that mat_elm returns the value of the original unscaled problem\n"); 137 | press_ret(); 138 | printf("If there are any integer type variables, then only the rows are scaled\n"); 139 | printf("set_int(lp1,3,FALSE);\n"); 140 | printf("auto_scale(lp1);\n"); 141 | set_int(lp1, 3, FALSE); 142 | auto_scale(lp1); 143 | print_lp(lp1); 144 | press_ret(); 145 | solve(lp1); 146 | printf("print_objective, print_solution gives the solution to the original problem\n"); 147 | print_objective(lp1); 148 | print_solution(lp1); 149 | press_ret(); 150 | printf("Scaling is turned off with unscale(lp1);\n"); 151 | unscale(lp1); 152 | print_lp(lp1); 153 | press_ret(); 154 | printf("Now turn B&B debugging off and simplex tracing on with\n"); 155 | printf("set_debug(lp1, FALSE), set_trace(lp1, TRUE) and solve(lp1)\n"); 156 | set_debug(lp1, FALSE); 157 | set_trace(lp1, TRUE); 158 | press_ret(); 159 | solve(lp1); 160 | printf("Where possible, lp_solve will start at the last found basis\n"); 161 | printf("We can reset the problem to the initial basis with\n"); 162 | printf("reset_basis(lp1). Now solve it again...\n"); 163 | press_ret(); 164 | reset_basis(lp1); 165 | solve(lp1); 166 | 167 | printf("It is possible to give variables and constraints names\n"); 168 | printf("set_row_name(lp1,1,\"speed\"); & set_col_name(lp1,2,\"money\")\n"); 169 | if (!set_row_name(lp1, 1, "speed")) 170 | ERROR(); 171 | if (!set_col_name(lp1, 2, "money")) 172 | ERROR(); 173 | print_lp(lp1); 174 | printf("As you can see, all column and rows are assigned default names\n"); 175 | printf("If a column or constraint is deleted, the names shift place also:\n"); 176 | press_ret(); 177 | printf("del_column(lp1,1);\n"); 178 | del_column(lp1, 1); 179 | print_lp(lp1); 180 | press_ret(); 181 | 182 | /* 183 | write_lp(lp1,"lp1.lp"); 184 | write_mps(lp1, "lp1.mps"); 185 | */ 186 | 187 | printf("A lp structure can be created and read from a .lp file\n"); 188 | printf("input_file=fopen(\"lp_examples/demo_lag.lp\",\"r\");\n"); 189 | printf("lp2 = read_lp_file(input_file, TRUE);\n"); 190 | printf("The verbose option is used\n"); 191 | input_file = fopen("lp_examples/demo_lag.lp", "r"); 192 | if (input_file == NULL) { 193 | printf("Can't find demo_lag.lp, stopping\n"); 194 | exit(EXIT_FAILURE); 195 | } 196 | if ((lp2 = read_lp_file(input_file, TRUE, "test")) == NULL) 197 | ERROR(); 198 | press_ret(); 199 | printf("lp2 is now:\n"); 200 | print_lp(lp2); 201 | /* 202 | write_lp(lp2, "lp2.lp"); 203 | */ 204 | press_ret(); 205 | printf("solution:\n"); 206 | set_debug(lp2, TRUE); 207 | solve(lp2); 208 | set_debug(lp2, FALSE); 209 | print_objective(lp2); 210 | print_solution(lp2); 211 | press_ret(); 212 | printf("You can see that branch & bound was used in this problem\n"); 213 | printf("Now remove the last constraint and use lagrangian relaxation\n"); 214 | printf("del_constraint(lp2,6);\n"); 215 | printf("str_add_lag_con(lp2, \"1 1 1 0 0 0\", LE, 2);\n"); 216 | del_constraint(lp2, 6); 217 | if (!str_add_lag_con(lp2, "1 1 1 0 0 0", LE, 2)) 218 | ERROR(); 219 | print_lp(lp2); 220 | /* 221 | write_lp(lp2, "lp2.lp"); 222 | */ 223 | printf("Lagrangian relaxation is used in some heuristics. It is now possible\n"); 224 | printf("to get a feasible integer solution without usage of branch & bound.\n"); 225 | printf("Use lag_solve(lp2, 0, 40); 0 is the initial bound, 30 the maximum\n"); 226 | printf("number of iterations, the last variable turns the verbose mode on.\n"); 227 | press_ret(); 228 | set_lag_trace(lp2, TRUE); 229 | printf("%d\n", lag_solve(lp2, 0, 30, TRUE)); 230 | printf("The returncode of lag_solve is 6 or FEAS_FOUND. this means that a feasible\n"); 231 | printf("solution has been found. For a list of other possible return values\n"); 232 | printf("see \"lpkit.h\". Print this solution with print_objective, print_solution\n"); 233 | print_objective(lp2); 234 | print_solution(lp2); 235 | /* 236 | write_lp(lp2, "lp2.lp"); 237 | write_mps(lp2, "lp2.mps"); 238 | */ 239 | press_ret(); 240 | 241 | return (0); 242 | } 243 | -------------------------------------------------------------------------------- /lp_solve_4.0/fortify.h: -------------------------------------------------------------------------------- 1 | #ifndef __FORTIFY_H__ 2 | #define __FORTIFY_H__ 3 | /* 4 | * FILE: 5 | * fortify.h 6 | * 7 | * DESCRIPTION: 8 | * Header file for fortify.c - A fortified shell for malloc, realloc, 9 | * calloc, strdup, getcwd, tempnam & free 10 | * 11 | * WRITTEN: 12 | * spb 29/4/94 13 | * 14 | * VERSION: 15 | * 1.0 29/4/94 16 | */ 17 | #include 18 | 19 | #include "declare.h" 20 | 21 | #if defined HP9000 || defined AViiON || defined ALPHA || defined SIGNED_UNKNOWN 22 | #define signed 23 | #endif 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #ifdef FORTIFY 30 | 31 | typedef void (*OutputFuncPtr) __OF((char *)); 32 | 33 | extern char *_Fortify_file; 34 | extern int _Fortify_line; 35 | 36 | #define Fortify_FILE(file) _Fortify_file=file 37 | #define Fortify_LINE(line) _Fortify_line=line 38 | 39 | #define _Fortify_FILE (_Fortify_file==(char *) 0 ? __FILE__ : _Fortify_file) 40 | #define _Fortify_LINE (_Fortify_line==0 ? __LINE__ : _Fortify_line) 41 | 42 | void _Fortify_Init __OF((char *file, unsigned long line)); 43 | void *_Fortify_malloc __OF((size_t size, char *file, unsigned long line)); 44 | void *_Fortify_realloc __OF((void *ptr, size_t new_size, char *file, unsigned long line)); 45 | void *_Fortify_calloc __OF((size_t nitems, size_t size, char *file, unsigned long line)); 46 | char *_Fortify_strdup __OF((char *str, char *file, unsigned long line)); 47 | char *_Fortify_getcwd __OF((char *buf, size_t size, char *file, unsigned long line)); 48 | char *_Fortify_tempnam __OF((char *dir, char *pfx, char *file, unsigned long line)); 49 | void _Fortify_free __OF((void *uptr, char *file, unsigned long line)); 50 | 51 | int _Fortify_OutputAllMemory __OF((char *file, unsigned long line)); 52 | int _Fortify_CheckAllMemory __OF((char *file, unsigned long line)); 53 | int _Fortify_CheckPointer __OF((void *uptr, char *file, unsigned long line)); 54 | int _Fortify_Disable __OF((char *file, unsigned long line, int how)); 55 | int _Fortify_SetMallocFailRate __OF((int Percent)); 56 | int _Fortify_EnterScope __OF((char *file, unsigned long line)); 57 | int _Fortify_LeaveScope __OF((char *file, unsigned long line)); 58 | int _Fortify_DumpAllMemory __OF((int scope, char *file, unsigned long line)); 59 | 60 | typedef void (*Fortify_OutputFuncPtr) __OF((/* const */ char *)); 61 | Fortify_OutputFuncPtr _Fortify_SetOutputFunc __OF((Fortify_OutputFuncPtr Output)); 62 | 63 | #endif /* FORTIFY */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #ifndef __FORTIFY_C__ /* Only define the macros if we're NOT in fortify.c */ 70 | 71 | #ifdef FORTIFY /* Add file and line information to the fortify calls */ 72 | 73 | #if defined malloc 74 | #undef malloc 75 | #endif 76 | #if defined realloc 77 | #undef realloc 78 | #endif 79 | #if defined calloc 80 | #undef calloc 81 | #endif 82 | #if defined strdup 83 | #undef strdup 84 | #endif 85 | #if defined getcwd 86 | #undef getcwd 87 | #endif 88 | #if defined tempnam 89 | #undef tempnam 90 | #endif 91 | #if defined free 92 | #undef free 93 | #endif 94 | 95 | #define malloc(size) _Fortify_malloc(size, _Fortify_FILE, _Fortify_LINE) 96 | #define realloc(ptr,new_size) _Fortify_realloc(ptr, new_size, _Fortify_FILE, _Fortify_LINE) 97 | #define calloc(num,size) _Fortify_calloc(num, size, _Fortify_FILE, _Fortify_LINE) 98 | #define strdup(str) _Fortify_strdup(str, _Fortify_FILE, _Fortify_LINE) 99 | #define getcwd(buf,size) _Fortify_getcwd(buf, size, _Fortify_FILE, _Fortify_LINE) 100 | #define tempnam(dir,pfx) _Fortify_tempnam(dir, pfx, _Fortify_FILE, _Fortify_LINE) 101 | #define free(ptr) _Fortify_free(ptr, _Fortify_FILE, _Fortify_LINE) 102 | 103 | #define Fortify_Init() _Fortify_Init(_Fortify_FILE, _Fortify_LINE) 104 | #define Fortify_OutputAllMemory() _Fortify_OutputAllMemory(_Fortify_FILE, _Fortify_LINE) 105 | #define Fortify_CheckAllMemory() _Fortify_CheckAllMemory(_Fortify_FILE, _Fortify_LINE) 106 | #define Fortify_CheckPointer(ptr) _Fortify_CheckPointer(ptr, _Fortify_FILE, _Fortify_LINE) 107 | #define Fortify_Disable(how) _Fortify_Disable(_Fortify_FILE, _Fortify_LINE,how) 108 | #define Fortify_EnterScope() _Fortify_EnterScope(_Fortify_FILE, _Fortify_LINE) 109 | #define Fortify_LeaveScope() _Fortify_LeaveScope(_Fortify_FILE, _Fortify_LINE) 110 | #define Fortify_DumpAllMemory(s) _Fortify_DumpAllMemory(s,_Fortify_FILE, _Fortify_LINE) 111 | 112 | #else /* FORTIFY Define the special fortify functions away to nothing */ 113 | 114 | #define Fortify_FILE(file) 115 | #define Fortify_LINE(line) 116 | #define Fortify_Init() 117 | #define Fortify_OutputAllMemory() 0 118 | #define Fortify_CheckAllMemory() 0 119 | #define Fortify_CheckPointer(ptr) 1 120 | #define Fortify_Disable(how) 1 121 | #define Fortify_SetOutputFunc() 0 122 | #define Fortify_SetMallocFailRate(p) 0 123 | #define Fortify_EnterScope() 0 124 | #define Fortify_LeaveScope() 0 125 | #define Fortify_DumpAllMemory(s) 0 126 | 127 | #endif /* FORTIFY */ 128 | #endif /* __FORTIFY_C__ */ 129 | #endif /* __FORTIFY_H__ */ 130 | -------------------------------------------------------------------------------- /lp_solve_4.0/hash.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "lpkit.h" /* only for MALLOC, CALLOC */ 4 | 5 | /* hash functions for open hashing */ 6 | 7 | hashstruct *create_hash_table(int size) { 8 | hashstruct *ht; 9 | 10 | if (MALLOC(ht, 1) != NULL) { 11 | if (CALLOC(ht->table, size) == NULL) { 12 | FREE(ht); 13 | } else 14 | ht->size = size; 15 | } 16 | return (ht); 17 | } 18 | 19 | void free_hash_table(hashstruct *ht) { 20 | int i; 21 | hashelem *hp, *thp; 22 | 23 | for (i = 0; i < ht->size; i++) { 24 | hp = ht->table[i]; 25 | while (hp != NULL) { 26 | thp = hp; 27 | hp = hp->next; 28 | free(thp->name); 29 | free(thp); 30 | } 31 | } 32 | free(ht->table); 33 | free(ht); 34 | } 35 | 36 | /* make a good hash function for any int size */ 37 | /* inspired by Aho, Sethi and Ullman, Compilers ..., p436 */ 38 | #define HASH_1 sizeof(unsigned int) 39 | #define HASH_2 (sizeof(unsigned int) * 6) 40 | #define HASH_3 (((unsigned int)0xF0) << ((sizeof(unsigned int) - 1) * CHAR_BIT)) 41 | 42 | static int hashval(const char *string, int size) { 43 | unsigned int result = 0, tmp; 44 | 45 | for (; *string; string++) { 46 | result = (result << HASH_1) + *string; 47 | if ((tmp = result & HASH_3) != 0) { 48 | /* if any of the most significant bits is on */ 49 | result ^= tmp >> HASH_2; /* xor them in in a less significant part */ 50 | result ^= tmp; /* and reset the most significant bits to 0 */ 51 | } 52 | } 53 | return (result % size); 54 | } /* hashval */ 55 | 56 | hashelem *findhash(const char *name, hashstruct *ht) { 57 | hashelem *h_tab_p; 58 | for (h_tab_p = ht->table[hashval(name, ht->size)]; 59 | h_tab_p != NULL; 60 | h_tab_p = h_tab_p->next) 61 | if (strcmp(name, h_tab_p->name) == 0) /* got it! */ 62 | break; 63 | return (h_tab_p); 64 | } /* gethash */ 65 | 66 | hashelem *puthash(const char *name, hashstruct *ht) { 67 | hashelem *hp; 68 | int index; 69 | 70 | if ((hp = findhash(name, ht)) == NULL) { 71 | index = hashval(name, ht->size); 72 | if (CALLOC(hp, 1) != NULL) { 73 | if (MALLOC(hp->name, strlen(name) + 1) == NULL) { 74 | FREE(hp); 75 | } else { 76 | strcpy(hp->name, name); 77 | hp->next = ht->table[index]; 78 | ht->table[index] = hp; 79 | } 80 | } 81 | } 82 | return (hp); 83 | } 84 | 85 | hashstruct *copy_hash_table(hashstruct *ht) { 86 | hashstruct *copy; 87 | hashelem *elem, *new_elem; 88 | int i; 89 | 90 | copy = create_hash_table(ht->size); 91 | if (copy != NULL) 92 | for (i = 0; i < ht->size; i++) { 93 | for (elem = ht->table[i]; elem != NULL; elem = elem->next) { 94 | if (CALLOC(new_elem, 1) == NULL) { 95 | free_hash_table(copy); 96 | return (NULL); 97 | } 98 | /* copy entire struct */ 99 | *new_elem = *elem; 100 | 101 | /* new line to duplicate name string */ 102 | if (MALLOC(new_elem->name, strlen(elem->name) + 1) == NULL) { 103 | free(new_elem); 104 | free_hash_table(copy); 105 | return (NULL); 106 | } 107 | strcpy(new_elem->name, elem->name); 108 | 109 | /* ... but link it into the new list */ 110 | new_elem->next = copy->table[i]; 111 | copy->table[i] = new_elem; 112 | } 113 | } 114 | 115 | return (copy); 116 | } 117 | -------------------------------------------------------------------------------- /lp_solve_4.0/hash.h: -------------------------------------------------------------------------------- 1 | #ifndef __HASH_H__ 2 | #define __HASH_H__ 3 | 4 | typedef struct _hashelem { 5 | char *name; 6 | struct _hashelem *next; 7 | struct _column *col; 8 | struct _bound *bnd; 9 | int must_be_int; 10 | int index; /* for row and column name hash tables */ 11 | } hashelem; 12 | 13 | typedef struct _hashstruct { 14 | hashelem **table; 15 | int size; 16 | } hashstruct; 17 | 18 | hashstruct *create_hash_table(int size); 19 | void free_hash_table(hashstruct *ht); 20 | hashelem *findhash(const char *name, hashstruct *ht); 21 | hashelem *puthash(const char *name, hashstruct *ht); 22 | hashstruct *copy_hash_table(hashstruct *ht); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /lp_solve_4.0/lex.l: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include "y.tab.h" 4 | %} 5 | 6 | WS [ \n\t]+ 7 | LT [A-Za-z] 8 | KR [A-Za-z0-9_\[\]\{\}/.&#$%~'@^] 9 | DI [0-9] 10 | NM {DI}*\.?{DI}+([Ee][-+]?{DI}+)? 11 | VR {LT}{KR}*(<{KR}+>)? 12 | S_OP [-+ \t\n]+ 13 | LOG [<>]?=? 14 | 15 | %start COMMENT 16 | 17 | %% 18 | "/*" { 19 | BEGIN COMMENT; 20 | } /* begin skip comment */ 21 | 22 | "*/" { 23 | BEGIN INITIAL; 24 | } /* end skip comment */ 25 | 26 | . { 27 | } 28 | 29 | \n { 30 | } 31 | 32 | {WS} { 33 | } 34 | 35 | "," { 36 | return(COMMA); 37 | } 38 | 39 | [mM][iI][nN]":" { 40 | return(MINIMISE); 41 | } 42 | 43 | [mM][aA][xX]":" { 44 | return(MAXIMISE); 45 | } 46 | 47 | {NM} { 48 | f = atof((char *)yytext); 49 | return(CONS); 50 | } /* f contains the last float */ 51 | 52 | {S_OP} { 53 | Sign = 0; 54 | for(x = 0; x < yyleng; x++) 55 | if(yytext[x] == '-' || yytext[x] == '+') 56 | Sign = (Sign == (yytext[x] == '+')); 57 | return (SIGN); 58 | /* Sign is TRUE if the sign-string 59 | represents a '-'. Otherwise Sign 60 | is FALSE */ 61 | } 62 | 63 | [Ii][Nn][Tt] { 64 | Within_int_decl = TRUE; 65 | return(VAR); 66 | } 67 | 68 | {VR} { 69 | strcpy(Last_var, (char *)yytext); 70 | return(VAR); 71 | } 72 | 73 | ":" { 74 | return (COLON); 75 | } 76 | 77 | "*" { 78 | return(AR_M_OP); 79 | } 80 | 81 | {LOG} { 82 | return(RE_OP); 83 | } 84 | 85 | ";" { 86 | Within_int_decl = FALSE; 87 | return(END_C); 88 | } 89 | 90 | . { 91 | report(NULL, CRITICALSTOP,"LEX ERROR : %s lineno %d \n" ,yytext,yylineno); 92 | } 93 | 94 | %% 95 | -------------------------------------------------------------------------------- /lp_solve_4.0/lp.y: -------------------------------------------------------------------------------- 1 | /* ========================================================================= */ 2 | /* NAME : lp.y */ 3 | /* ========================================================================= */ 4 | 5 | %token VAR CONS SIGN AR_M_OP RE_OP END_C COMMA COLON MINIMISE MAXIMISE 6 | 7 | %{ 8 | #include 9 | 10 | #include "lpkit.h" 11 | #include "lpglob.h" 12 | #include "read.h" 13 | 14 | /* globals */ 15 | char Last_var[NAMELEN]; 16 | int Lin_term_count; 17 | REAL f; 18 | int x; 19 | int Sign; 20 | int isign; /* internal_sign variable to make sure nothing goes wrong */ 21 | /* with lookahead */ 22 | int make_neg; /* is true after the relational operator is seen in order */ 23 | /* to remember if lin_term stands before or after re_op */ 24 | int Within_int_decl = FALSE; /* TRUE when we are within an int declaration */ 25 | 26 | #include "lex.c" 27 | %} 28 | 29 | 30 | 31 | %start inputfile 32 | %% 33 | 34 | inputfile : 35 | { 36 | if(!init_read()) 37 | report(NULL, CRITICALSTOP, "init_read failed"); 38 | isign = 0; 39 | make_neg = 0; 40 | Sign = 0; 41 | } 42 | objective_function 43 | constraints 44 | int_declarations 45 | ; 46 | 47 | constraints : constraint 48 | | constraints 49 | constraint 50 | ; 51 | 52 | constraint : real_constraint 53 | | VAR COLON 54 | { 55 | if(!add_constraint_name(Last_var, Rows)) 56 | report(NULL, CRITICALSTOP, "add_constraint_name failed"); 57 | } 58 | real_constraint 59 | ; 60 | 61 | 62 | real_constraint : xx_lineair_sum 63 | RE_OP 64 | { 65 | store_re_op(); 66 | make_neg = 1; 67 | } 68 | x_lineair_sum 69 | END_C 70 | { 71 | if(Lin_term_count == 0) { 72 | /* it is a range */ 73 | /* already handled */ 74 | } 75 | else if(Lin_term_count == 1) { 76 | /* it is a bound */ 77 | 78 | if(!store_bounds()) 79 | report(NULL, CRITICALSTOP, "store_bounds failed"); 80 | } 81 | else { 82 | /* it is a row restriction */ 83 | Rows++; 84 | } 85 | 86 | Lin_term_count = 0; 87 | isign = 0 ; 88 | make_neg = 0; 89 | } 90 | ; 91 | 92 | int_declarations: /* EMPTY */ 93 | | real_int_decls 94 | ; 95 | 96 | real_int_decls : int_declaration 97 | | real_int_decls int_declaration 98 | ; 99 | 100 | int_declaration : int_declarator vars END_C 101 | ; 102 | 103 | int_declarator : VAR {check_decl(Within_int_decl);} 104 | ; 105 | 106 | vars : VAR {if(!Ignore_decl)add_int_var((char *)yytext);} 107 | | vars VAR {if(!Ignore_decl)add_int_var((char *)yytext);} 108 | | vars COMMA VAR {if(!Ignore_decl)add_int_var((char *)yytext);} 109 | ; 110 | 111 | x_lineair_sum : x_lineair_term 112 | | SIGN 113 | { 114 | isign = Sign; 115 | } 116 | x_lineair_term 117 | | x_lineair_sum 118 | SIGN 119 | { 120 | isign = Sign; 121 | } 122 | x_lineair_term 123 | ; 124 | 125 | x_lineair_term : lineair_term 126 | | CONS 127 | { 128 | if ( (isign || !make_neg) 129 | && !(isign && !make_neg)) /* but not both! */ 130 | f = -f; 131 | rhs_store(f); 132 | isign = 0; 133 | } 134 | ; 135 | 136 | lineair_sum : lineair_term 137 | | SIGN 138 | { 139 | isign = Sign; 140 | } 141 | lineair_term 142 | | lineair_sum 143 | SIGN 144 | { 145 | isign = Sign; 146 | } 147 | lineair_term 148 | ; 149 | 150 | lineair_term : VAR 151 | { 152 | if ( (isign || make_neg) 153 | && !(isign && make_neg)) { /* but not both! */ 154 | if(!var_store(Last_var, Rows, (REAL) -1)) 155 | report(NULL, CRITICALSTOP, "var_store failed"); 156 | } 157 | else { 158 | if(!var_store(Last_var, Rows, (REAL) 1)) 159 | report(NULL, CRITICALSTOP, "var_store failed"); 160 | } 161 | isign = 0; 162 | } 163 | | CONS 164 | VAR 165 | { 166 | if ( (isign || make_neg) 167 | && !(isign && make_neg)) /* but not both! */ 168 | f = -f; 169 | if(!var_store(Last_var, Rows, f)) 170 | report(NULL, CRITICALSTOP, "var_store failed"); 171 | isign = 0; 172 | } 173 | | CONS 174 | AR_M_OP 175 | VAR 176 | { 177 | if ( (isign || make_neg) 178 | && !(isign && make_neg)) /* but not both! */ 179 | f = -f; 180 | if(!var_store(Last_var, Rows, f)) 181 | report(NULL, CRITICALSTOP, "var_store failed"); 182 | isign = 0; 183 | } 184 | ; 185 | 186 | xx_lineair_sum: /* EMPTY */ 187 | | x_lineair_sum 188 | ; 189 | 190 | objective_function: MAXIMISE real_of 191 | { 192 | Maximise = TRUE; 193 | } 194 | | MINIMISE real_of 195 | { 196 | Maximise = FALSE; 197 | } 198 | | real_of 199 | ; 200 | 201 | real_of: lineair_sum 202 | END_C 203 | { 204 | Rows++; 205 | Lin_term_count = 0; 206 | isign = 0; 207 | make_neg = 0; 208 | } 209 | | END_C /* allow empty OF */ 210 | { 211 | Rows++; 212 | Lin_term_count = 0; 213 | isign = 0; 214 | make_neg = 0; 215 | } 216 | ; 217 | %% 218 | -------------------------------------------------------------------------------- /lp_solve_4.0/lp2mps.c: -------------------------------------------------------------------------------- 1 | #include "lpkit.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | lprec *lp; 6 | FILE *fpin, *fpout; 7 | int i; 8 | 9 | for (i = 1; i < argc; i++) 10 | if (argv[i][0] == '-') { 11 | printf("lp to mps file converter\n"); 12 | printf("Usage: lp2mps [inputfile.lp [outputfile.mps]] [outputfile.mps]\n"); 13 | return (1); 14 | } 15 | 16 | if (argc >= 2) { 17 | fpin = fopen(argv[1], "r"); 18 | if (fpin == NULL) { 19 | fprintf(stderr, "Unable to open input file %s\n", argv[1]); 20 | return (2); 21 | } 22 | } else 23 | fpin = stdin; 24 | 25 | if (argc >= 3) { 26 | fpout = fopen(argv[2], "w"); 27 | if (fpout == NULL) { 28 | fprintf(stderr, "Unable to open output file %s\n", argv[2]); 29 | return (3); 30 | } 31 | } else 32 | fpout = stdout; 33 | 34 | fprintf(stderr, "reading lp file\n"); 35 | lp = read_lp_file(fpin, FALSE, "from_lp_file"); 36 | if (fpin != stdin) 37 | fclose(fpin); 38 | 39 | if (lp == NULL) { 40 | fprintf(stderr, "Unable to read lp file\n"); 41 | return (4); 42 | } else { 43 | fprintf(stderr, "writing mps file\n"); 44 | if (!write_MPS(lp, fpout)) { 45 | fprintf(stderr, "Unable to write mps file\n"); 46 | return (5); 47 | } 48 | } 49 | if (fpout != stdout) 50 | fclose(fpout); 51 | 52 | return (0); 53 | } 54 | -------------------------------------------------------------------------------- /lp_solve_4.0/lp_solve.1: -------------------------------------------------------------------------------- 1 | .\" -*-nroff-*- 2 | .TH LP_SOLVE 1 "November 30, 2002" 3 | .SH NAME 4 | lp_solve \- solve (mixed integer) linear programming problems 5 | .SH SYNOPSIS 6 | \fBlp_solve\fP [\fIoptions\fP] < \fIinput-file\fP 7 | .SH OPTIONS 8 | .TP 1.2i 9 | -v[\fIlevel\fP] 10 | Set verbosity: 11 | .nf 12 | -v0: CRITICALSTOP 13 | -v1: CRITICAL 14 | -v2: SEVERE 15 | -v3: IMPORTANT (default) 16 | -v4: NORMAL 17 | -v5: DETAILED 18 | -v6: FULL 19 | .fi 20 | If level not provided (-v) then -v4 (NORMAL) is assumed. 21 | -time 22 | Print CPU time to parse input and to calculate result. 23 | .TP 24 | -S\fIdetail\fP 25 | Print solution. If \fIdetail\fP omitted, then -S2 is used. 26 | .nf 27 | -S0: Print nothing 28 | -S1: Only objective value 29 | -S2: Objective value + variables (default) 30 | -S3: Objective value + variables + constraints 31 | -S4: Objective value + variables + constraints + duals 32 | -S5: Objective value + variables + constraints + duals + lp model 33 | -S6: Objective value + variables + constraints + duals + lp model + lp scales 34 | .fi 35 | .TP 36 | -h 37 | Help mode, prints the usage. 38 | .TP 39 | -d 40 | Debug mode, all intermediate results are printed, and the branch-and-bound 41 | decisions in case of (mixed) integer problems. 42 | .TP 43 | -min 44 | Minimize the objective function. This is the default for MPS input. 45 | In lp_solve format you can specify minimization or maximization in the input 46 | file as well. The command line option overrides. 47 | .TP 48 | -max 49 | Maximize the objective function. This is the default for lp_solve format 50 | input. 51 | In lp_solve format you can specify minimization or maximization in the input 52 | file as well. The command line option overrides. 53 | .TP 54 | -p 55 | Only functional for pure LP problems. Print the values of the dual 56 | variables as well in the result. They are named r_1 until r_XXXXX unless 57 | specified by the user. Note that bounds (constraints on just one variable) 58 | are not considered real constraints, and are not given a row in the matrix, 59 | and are therefore not printed here. 60 | .TP 61 | -b \fIbound\fP 62 | Specify an upper (when minimizing) or lower (when maximizing) limit for the 63 | value of the objective function to 64 | the program. Only useful for (mixed) integer problems. If close enough, may 65 | speed up the calculations. The same result can be obtained by adding an extra 66 | constraint to the problem. 67 | .TP 68 | -c 69 | When branching in MILP problems, take the ceiling of the selected non-integer 70 | variable first instead of the floor. This can influence the speed of MILP 71 | problems. 72 | .TP 73 | -B 74 | -B \fIrule\fP 75 | Specify branch-and-bound rule: 76 | .nf 77 | -B0: Select Lowest indexed non-integer column (default) 78 | -B1: Select Random non-integer column 79 | -B2: Select Largest deviation from an integer value 80 | -B3: Select Best ??? 81 | -B4: Select Median value deviation from an integer value 82 | -B5: Select Greedy ??? 83 | .fi 84 | .TP 85 | -e \fIvalue\fP 86 | \fIvalue\fP is the tolerance of the test for whether the value of a variable 87 | is really integer. \fIvalue\fP must be between 0 and 0.5. Default value is 1e-6 88 | and should be OK for most applications. Of course only useful for MILP 89 | problems. 90 | .TP 91 | -i 92 | Print all intermediate valid solutions. Can give you useful 93 | solutions even if the total run time is too long. 94 | Only useful for (mixed) integer problems. 95 | .TP 96 | -s \fImode\fP 97 | Use automatic problem scaling: 98 | .nf 99 | -s: 100 | -s0: Numerical range-based scaling 101 | -s1: Geometric scaling 102 | -s2: Curtis-reid scaling 103 | .fi 104 | This might improve the numerical 105 | stability of your problem. 106 | .TP 107 | -sp 108 | Also do power scaling. 109 | This option must come AFTER -s \fImode\fP option. 110 | .TP 111 | -sl 112 | Also do Lagrange scaling. 113 | This option must come AFTER -s \fImode\fP option. 114 | .TP 115 | -si 116 | Also do Integer scaling. 117 | This option must come AFTER -s \fImode\fP option. 118 | .TP 119 | -I 120 | Print info after reinverting. 121 | .TP 122 | -t 123 | Trace pivot selection. 124 | .TP 125 | -lp 126 | Read from LP file (default). 127 | .TP 128 | -mps 129 | Read from MPS file instead of lp file. For a short introduction to MPS see 130 | ftp://softlib.cs.rice.edu/pub/miplib/mps_format. 131 | .TP 132 | -parse_only 133 | Parse input file but do not calculate (ie check). 134 | .TP 135 | -presolve 136 | Presolve problem before optimizing. 137 | .TP 138 | -improve\fIlevel\fP 139 | Iterative improvement level: 140 | .nf 141 | -improve0: none (default) 142 | -improve1: FTRAN only 143 | -improve2: BTRAN only 144 | -improve3: FTRAN + BTRAN 145 | .fi 146 | .TP 147 | -degen 148 | Use random perturbations to reduce degeneracy, can increase numerical 149 | instability. 150 | .TP 151 | -trej \fITrej\fP 152 | Set minimum pivot value to \fITrej\fP. 153 | .SH DESCRIPTION 154 | The linear programming problem can be formulated as: Solve A.x >= V1, with 155 | V2.x maximal. A is a matrix, x a vector of (nonnegative) variables, V1 a 156 | vector called the right hand side, and V2 a vector specifying the objective 157 | function. 158 | .br 159 | Any number of the variables may be specified to be of type integer. 160 | .br 161 | This program solves problems of this kind. It is slightly more general than 162 | the above problem, in that every row of A (specifying one constraint) can have 163 | its own (in)equality, <=, >= or =. The result specifies values for all 164 | variables. 165 | .br 166 | Uses a 'Simplex' algorithm and sparse matrix methods, for pure LP problems. 167 | If one or more of the variables is declared integer, the Simplex algorithm is 168 | iterated with a branch and bound algorithm, until the desired optimal 169 | solution is found. 170 | .br 171 | The "-i" option will print all intermediate valid solutions. 172 | .SH "INPUT SYNTAX" 173 | The default input syntax is a set of algebraic expressions and "int" 174 | declarations in the following order: 175 | .sp 176 | 177 | .br 178 | + 179 | .br 180 | * 181 | .sp 182 | where: 183 | .TP 0.2i 184 | - 185 | is a linear combination of variables, ending with a 186 | semicolon, optionally preceded by "max: " or "min: " to indicate whether you 187 | want it to be minimized or maximized. The case is not important, "Max:" or 188 | "MAX:" will work as well. Maximization is the default. 189 | .TP 190 | - 191 | is an optional constraint name followed by a colon plus a 192 | linear combination of variables and constants, followed by a relational 193 | operator, followed again by a linear combination of variables and constants, 194 | ending with a semicolon. The relational operator can be any of the following: 195 | "<" "<=" "=" ">" ">=". There is no semantic difference between "<" and "<=" 196 | nor between ">" and ">=" (even for integer variables!). 197 | .TP 198 | - 199 | is of the form: "int" \fIvar\fP+ ";" Commas are allowed between 200 | variables. 201 | .sp 202 | So, the simplest linear problem consists of an objective function and 1 203 | constraint. 204 | .SH EXAMPLE 205 | The simple problem: 206 | .sp 207 | x1 >= 1 208 | .br 209 | x2 >= 1 210 | .br 211 | x1 + x2 >= 2 212 | .br 213 | minimize x1 + x2 (= maximize -(x1 + x2)), with x1 integer 214 | .sp 215 | can be written as follows: 216 | .sp 217 | -x1 + -x2; 218 | .br 219 | (or min: x1 + x2;) 220 | .br 221 | x1 > 1; 222 | .br 223 | x2 > 1; 224 | .br 225 | x1 + x2 > 2; 226 | .br 227 | int x1; 228 | .sp 229 | The correct result for (x1, x2) is of course (1, 1). 230 | .br 231 | With the -mps option, \fBlp_solve\fP will accept MPS as input format. 232 | .SH BUGS 233 | Specifying a constraint name for a bound (constraints on just single 234 | variables) does not have an effect: they are not stored inside the main matrix 235 | and are not assigned a dual variable. 236 | .TP 237 | - 238 | The problem consists entirely of constraints on just single variables 239 | (so-called "bounds", like x < 1; ) and no constraint with more than 1 240 | variable (like x + 3 y > 17; ). This leaves \fBlp_solve\fP with an empty problem 241 | matrix, as bounds are not stored in the main matrix. No real-life examples 242 | should be of this form, so I am not really chasing this problem. 243 | .TP 244 | - 245 | Many people forget that \fBlp_solve\fP can only handle POSITIVE values for the 246 | variables. While reading MPS files it will however handle free or negative 247 | variables by replacing them with a variable pair \fIvar\fP_neg and \fIvar\fP_pos or 248 | -\fIvar\fP respectively. It is up to the user to interpret the result of this 249 | transformation. 250 | .TP 251 | - Sometimes problems are numerically unstable, and the unavoidable rounding 252 | errors inside \fBlp_solve\fP will cause aborts. It is very hard to give general 253 | solutions to this problem, but try to keep all values in your problem in the 254 | order of magnitude of 1 by proper scaling. This is almost always better than 255 | using \fBlp_solve\fPs built-in scaling (with -s). Almost parallel constraints are 256 | also not very good for numerical stability. Use "lp_solve -v" and observe the 257 | values of the pivots to see if there are any dangerously large or low numbers 258 | there. 259 | .br 260 | Building \fBlp_solve\fP with long doubles (see the Makefile) can help to increase 261 | numerical stability, but will also increase the run time considerably. 262 | .br 263 | You can consult the author as well if you encounter numerical problems, but 264 | please remember that it is very easy to formulate an infeasible LP problem, so 265 | be sure there is a solution. 266 | .SH SEE ALSO 267 | The implementation of the simplex kernel was mainly based on: 268 | .br 269 | W. Orchard-Hays: "Advanced Linear Programming Computing Techniques", 270 | McGraw-Hill 1968 271 | .br 272 | The mixed integer branch and bound part was inspired by: 273 | .br 274 | section 6.4 of "An Introduction to Linear Programming and Game Theory" by 275 | Paul R. Thie, second edition published by John Wiley and Sons in 1988. 276 | .br 277 | This book refers to: 278 | .br 279 | Dakin, R.J., "A Tree Search Algorithm for MILP Problems", Comput. J., 8 (1965) 280 | pp. 250-255 281 | .SH ACKNOWLEDGEMENTS 282 | The work of Jeroen Dirks made the transition from the basic version 1.5 to 283 | the full version 2.0 possible. He contributed the procedural interface, a 284 | built-in MPS reader, and many fixes and enhancements to the code. 285 | .SH CONTRIBUTED BY 286 | M.R.C.M. Berkelaar 287 | .br 288 | Eindhoven University of Technology 289 | .br 290 | Design Automation Section 291 | .br 292 | P.O. Box 513 293 | .br 294 | NL-5600 MB Eindhoven, The Netherlands 295 | .br 296 | phone +31-40-2474792 297 | .br 298 | E-mail: michel@es.ele.tue.nl 299 | .SH STATUS 300 | Use at own risk. Bug reports are welcome, as well as success stories. 301 | -------------------------------------------------------------------------------- /lp_solve_4.0/lp_solve.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "lpkit.h" 4 | #include "lpglob.h" 5 | #include "patchlevel.h" 6 | 7 | #if defined FORTIFY 8 | 9 | int EndOfPgr() { 10 | exit(1); 11 | return (0); 12 | } 13 | #endif 14 | 15 | void print_help(char *argv[]) { 16 | printf("Usage of %s version %d.%d.%d.%d:\n", argv[0], MAJORVERSION, MINORVERSION, RELEASE, BUILD); 17 | printf("%s [options] [[<]input_file]\n", argv[0]); 18 | printf("List of options:\n"); 19 | printf("-h\t\tprints this message\n"); 20 | printf("-v \tverbose mode, gives flow through the program.\n"); 21 | printf("\t\t if level not provided (-v) then -v2 (NORMAL) is taken.\n"); 22 | printf("\t -v0: CRITICALSTOP\n"); 23 | printf("\t -v1: CRITICAL\n"); 24 | printf("\t -v2: SEVERE\n"); 25 | printf("\t -v3: IMPORTANT (default)\n"); 26 | printf("\t -v4: NORMAL\n"); 27 | printf("\t -v5: DETAILED\n"); 28 | printf("\t -v6: FULL\n"); 29 | printf("-d\t\tdebug mode, all intermediate results are printed,\n\t\tand the branch-and-bound decisions\n"); 30 | printf("-p\t\tprint the values of the dual variables\n"); 31 | printf("-b \tspecify a lower bound for the objective function\n\t\tto the program. If close enough, may speed up the\n\t\tcalculations.\n"); 32 | printf("-i\t\tprint all intermediate valid solutions.\n\t\tCan give you useful solutions even if the total run time\n\t\tis too long\n"); 33 | printf("-e \tspecifies the epsilon which is used to determine whether a\n\t\tfloating point number is in fact an integer.\n\t\tShould be < 0.5\n"); 34 | printf("-c\t\tduring branch-and-bound, take the ceiling branch first\n"); 35 | printf("-ca\t\tduring branch-and-bound, the algorithm chooses branch\n"); 36 | printf("-B \tspecify branch-and-bound rule\n"); 37 | printf("\t -B0: Select Lowest indexed non-integer column (default)\n"); 38 | printf("\t -B1: Select Random non-integer column\n"); 39 | printf("\t -B2: Select Largest deviation from an integer value\n"); 40 | printf("\t -B3: Select Best ???\n"); 41 | printf("\t -B4: Select Median value deviation from an integer value\n"); 42 | printf("\t -B5: Select Greedy ???\n"); 43 | printf("-s \tuse automatic problem scaling.\n"); 44 | printf("\t -s:\n"); 45 | printf("\t -s0: Numerical range-based scaling\n"); 46 | printf("\t -s1: Geometric scaling\n"); 47 | printf("\t -s2: Curtis-reid scaling\n"); 48 | printf("-sp\t\talso do power scaling.\n\t\tThis option must come AFTER -s option\n"); 49 | printf("-sl\t\talso do Lagrange scaling.\n\t\tThis option must come AFTER -s option\n"); 50 | printf("-si\t\talso do Integer scaling.\n\t\tThis option must come AFTER -s option\n"); 51 | printf("-I\t\tprint info after reinverting\n"); 52 | printf("-t\t\ttrace pivot selection\n"); 53 | printf("-lp\t\tread from LP file (default)\n"); 54 | printf("-mps\t\tread from MPS file\n"); 55 | printf("-degen\t\tuse perturbations to reduce degeneracy,\n\t\tcan increase numerical instability\n"); 56 | printf("-trej \tset minimum pivot value\n"); 57 | printf("-parse_only\tparse input file but do not calculate (ie check)\n"); 58 | printf("-presolve\tpresolve problem before start optimizing\n"); 59 | printf("-improve \titerative improvement level\n"); 60 | printf("\t -improve0: none (default)\n"); 61 | printf("\t -improve1: FTRAN only\n"); 62 | printf("\t -improve2: BTRAN only\n"); 63 | printf("\t -improve3: FTRAN + BTRAN\n"); 64 | printf("-time\t\tPrint CPU time to parse input and to calculate result\n"); 65 | printf("-min\t\tMinimize the lp problem (overrules setting in file)\n"); 66 | printf("-max\t\tMaximize the lp problem (overrules setting in file)\n"); 67 | printf("-S \tPrint solution. If detail ommited, then -S2 is used.\n"); 68 | printf("\t -S0: Print nothing\n"); 69 | printf("\t -S1: Only objective value\n"); 70 | printf("\t -S2: Objective value + variables (default)\n"); 71 | printf("\t -S3: Objective value + variables + constraints\n"); 72 | printf("\t -S4: Objective value + variables + constraints + duals\n"); 73 | printf("\t -S5: Objective value + variables + constraints + duals + lp model\n"); 74 | printf("\t -S6: Objective value + variables + constraints + duals + lp model + lp scales\n"); 75 | } 76 | 77 | void print_cpu_times(const char *info) { 78 | static clock_t last_time = 0; 79 | clock_t new_time; 80 | 81 | new_time = clock(); 82 | fprintf(stderr, "CPU Time for %s: %gs (%gs total since program start)\n", 83 | info, (new_time - last_time) / (double) CLOCKS_PER_SEC, 84 | new_time / (double) CLOCKS_PER_SEC); 85 | last_time = new_time; 86 | } 87 | 88 | int main(int argc, char *argv[]) { 89 | lprec *lp; 90 | char *filen; 91 | int i; 92 | short verbose = IMPORTANT /* CRITICALSTOP */; 93 | MYBOOL debug = FALSE; 94 | MYBOOL print_sol = FALSE; 95 | MYBOOL PRINT_DUALS = FALSE; 96 | MYBOOL floor_first = TRUE; 97 | short scaling = 0; 98 | short print_at_invert = FALSE; 99 | MYBOOL tracing = FALSE; 100 | short mps = FALSE; 101 | MYBOOL anti_degen = FALSE; 102 | short print_timing = FALSE; 103 | short parse_only = FALSE; 104 | MYBOOL do_presolve = FALSE; 105 | short objective = 0; 106 | short PRINT_SOLUTION = 2; 107 | MYBOOL improve = IMPROVE_NONE; 108 | MYBOOL bb_rule = FIRST_SELECT; 109 | MYBOOL scalemode = MMSCALING; 110 | int result; 111 | REAL obj_bound = (REAL) DEF_INFINITE; 112 | REAL epsilon = (REAL) DEF_EPSILON; 113 | REAL epspivot = (REAL) DEF_EPSPIVOT; 114 | FILE *fpin = stdin; 115 | 116 | /* read command line arguments */ 117 | 118 | #if defined FORTIFY 119 | Fortify_EnterScope(); 120 | #endif 121 | 122 | for (i = 1; i < argc; i++) { 123 | if (strncmp(argv[i], "-v", 2) == 0) { 124 | if (argv[i][2]) 125 | verbose = (short) atoi(argv[i] + 2); 126 | else 127 | verbose = NORMAL; 128 | } else if (strcmp(argv[i], "-d") == 0) 129 | debug = TRUE; 130 | else if (strcmp(argv[i], "-i") == 0) 131 | print_sol = TRUE; 132 | else if (strcmp(argv[i], "-c") == 0) 133 | floor_first = FALSE; 134 | else if (strcmp(argv[i], "-ca") == 0) 135 | floor_first = AUTOMATIC; 136 | else if (strncmp(argv[i], "-B", 2) == 0) { 137 | if (argv[i][2]) 138 | bb_rule = (MYBOOL) atoi(argv[i] + 2); 139 | else 140 | bb_rule = FIRST_SELECT; 141 | } else if (strcmp(argv[i], "-b") == 0) 142 | obj_bound = atof(argv[++i]); 143 | else if (strcmp(argv[i], "-e") == 0) { 144 | epsilon = atof(argv[++i]); 145 | if ((epsilon <= 0.0) || (epsilon >= 0.5)) { 146 | fprintf(stderr, "Invalid epsilon %g; 0 < epsilon < 0.5\n", 147 | (double) epsilon); 148 | exit(EXIT_FAILURE); 149 | } 150 | } else if (strcmp(argv[i], "-p") == 0) 151 | PRINT_DUALS = TRUE; 152 | else if (strcmp(argv[i], "-h") == 0) { 153 | print_help(argv); 154 | exit(EXIT_SUCCESS); 155 | } else if (strcmp(argv[i], "-sp") == 0) 156 | scalemode = (MYBOOL) (scalemode | POWERSCALE); 157 | else if (strcmp(argv[i], "-sl") == 0) 158 | scalemode = (MYBOOL) (scalemode | LAGRANGESCALE); 159 | else if (strcmp(argv[i], "-s2") == 0) 160 | scaling = 2; 161 | else if (strcmp(argv[i], "-si") == 0) 162 | scalemode = (MYBOOL) (scalemode | INTEGERSCALE); 163 | else if (strncmp(argv[i], "-s", 2) == 0) { 164 | scaling = 1; 165 | if (argv[i][2]) 166 | scalemode = (MYBOOL) atoi(argv[i] + 2); 167 | else 168 | scalemode = MMSCALING; 169 | } else if (strcmp(argv[i], "-I") == 0) 170 | print_at_invert = TRUE; 171 | else if (strcmp(argv[i], "-t") == 0) 172 | tracing = TRUE; 173 | else if (strncmp(argv[i], "-S", 2) == 0) { 174 | if (argv[i][2]) 175 | PRINT_SOLUTION = (short) atoi(argv[i] + 2); 176 | else 177 | PRINT_SOLUTION = 2; 178 | } else if (strncmp(argv[i], "-improve", 8) == 0) { 179 | if (argv[i][8]) 180 | improve = (MYBOOL) atoi(argv[i] + 8); 181 | else 182 | improve = 0; 183 | } else if (strcmp(argv[i], "-mps") == 0) 184 | mps = TRUE; 185 | else if (strcmp(argv[i], "-lp") == 0) 186 | mps = FALSE; 187 | else if (strcmp(argv[i], "-degen") == 0) 188 | anti_degen = TRUE; 189 | else if (strcmp(argv[i], "-time") == 0) { 190 | if (clock() == -1) 191 | fprintf(stderr, "CPU times not available on this machine\n"); 192 | else 193 | print_timing = TRUE; 194 | } else if (strcmp(argv[i], "-trej") == 0) 195 | epspivot = atof(argv[++i]); 196 | else if (strcmp(argv[i], "-parse_only") == 0) 197 | /* only useful for parser software development */ 198 | parse_only = TRUE; 199 | else if (strcmp(argv[i], "-presolve") == 0) 200 | do_presolve = TRUE; 201 | else if (strcmp(argv[i], "-min") == 0) 202 | objective = -1; 203 | else if (strcmp(argv[i], "-max") == 0) 204 | objective = 1; 205 | else if (fpin == stdin) { 206 | filen = argv[i]; 207 | if (*filen == '<') 208 | filen++; 209 | if ((fpin = fopen(filen, "r")) == NULL) { 210 | fprintf(stderr, "Error, Unable to open input file '%s'\n", 211 | argv[i]); 212 | print_help(argv); 213 | exit(EXIT_FAILURE); 214 | } 215 | } else { 216 | filen = argv[i]; 217 | if (*filen != '>') { 218 | fprintf(stderr, "Error, Unrecognized command line argument '%s'\n", 219 | argv[i]); 220 | print_help(argv); 221 | exit(EXIT_FAILURE); 222 | } 223 | } 224 | } 225 | 226 | if (mps) 227 | lp = read_mps(fpin, verbose); 228 | else /* standard lp_solve syntax expected */ 229 | lp = read_lp_file(fpin, verbose, "lp"); 230 | 231 | if (fpin != stdin) 232 | fclose(fpin); 233 | 234 | if (print_timing) 235 | print_cpu_times("Parsing input"); 236 | 237 | if (parse_only) 238 | exit(0); 239 | 240 | if (lp == NULL) { 241 | fprintf(stderr, "Unable to read model.\n"); 242 | exit(EXIT_FAILURE); 243 | } 244 | 245 | if (objective != 0) { 246 | if (objective == 1) 247 | set_maxim(lp); 248 | else 249 | set_minim(lp); 250 | } 251 | 252 | if (PRINT_SOLUTION >= 5) 253 | print_lp(lp); 254 | 255 | set_print_sol(lp, print_sol); 256 | set_epsilon(lp, epsilon); 257 | set_epspivot(lp, epspivot); 258 | set_print_duals(lp, PRINT_DUALS); 259 | set_debug(lp, debug); 260 | set_floor_first(lp, floor_first); 261 | set_print_at_invert(lp, print_at_invert); 262 | set_trace(lp, tracing); 263 | if (obj_bound != DEF_INFINITE) 264 | set_obj_bound(lp, obj_bound); 265 | set_anti_degen(lp, anti_degen); 266 | set_do_presolve(lp, do_presolve); 267 | set_improve(lp, improve); 268 | set_scalemode(lp, scalemode); 269 | set_bb_rule(lp, bb_rule); 270 | 271 | if (scaling == 1) 272 | auto_scale(lp); 273 | if (scaling == 2) 274 | scaleCR(lp); 275 | 276 | if (PRINT_SOLUTION >= 6) 277 | print_scales(lp); 278 | 279 | result = solve(lp); 280 | 281 | if (print_timing) 282 | print_cpu_times("solving"); 283 | 284 | if (result == OPTIMAL) { 285 | if (PRINT_SOLUTION >= 1) 286 | print_objective(lp); 287 | 288 | if (PRINT_SOLUTION >= 2) 289 | print_solution(lp); 290 | 291 | if (PRINT_SOLUTION >= 3) 292 | print_constraints(lp); 293 | 294 | if (PRINT_SOLUTION >= 4) 295 | print_duals(lp); 296 | 297 | if (tracing) 298 | fprintf(stderr, 299 | "Branch & Bound depth: %d\nNodes processed: %d\nSimplex pivots: %d\n", 300 | get_max_level(lp), get_total_nodes(lp), get_total_iter(lp)); 301 | } else if (result == INFEASIBLE) { 302 | if (PRINT_SOLUTION >= 1) 303 | printf("This problem is infeasible\n"); 304 | } else if (result == UNBOUNDED) { 305 | if (PRINT_SOLUTION >= 1) 306 | printf("This problem is unbounded\n"); 307 | } else if (result == FAILURE) { 308 | if (PRINT_SOLUTION >= 1) 309 | printf("lp_solve failed\n"); 310 | } 311 | 312 | delete_lp(lp); 313 | 314 | #if defined FORTIFY 315 | Fortify_LeaveScope(); 316 | #endif 317 | 318 | return (result); 319 | } 320 | -------------------------------------------------------------------------------- /lp_solve_4.0/lp_solve.man: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinlb1/CATS/38cbf35f5c36796522cb76895fd6388f0dd63f5c/lp_solve_4.0/lp_solve.man -------------------------------------------------------------------------------- /lp_solve_4.0/lpglob.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifndef __LPGLOB_H__ 4 | #define __LPGLOB_H__ 5 | 6 | /* Globals for parser */ 7 | 8 | extern int Rows; 9 | extern int Columns; 10 | extern int Non_zeros; 11 | 12 | extern FILE *yyin; 13 | extern FILE *lpfilename; 14 | extern short Maximise; 15 | extern short *relat; 16 | extern int yylineno; 17 | extern int yyleng; 18 | extern int Lin_term_count; 19 | extern int Sign; 20 | extern constraint_name *First_constraint_name; 21 | /* I hate #ifdefs, but there seems to be no "standard" way to do this */ 22 | #if defined(__hpux) || defined(__apollo) || defined(_AIX) || defined(_OSF_SOURCE) 23 | /* for HP/UX, Apollo, AIX, DEC OSF */ 24 | extern unsigned char yytext[]; 25 | #else 26 | /* For other computers */ 27 | extern char yytext[]; 28 | #endif 29 | 30 | extern rside *First_rside; 31 | extern short Ignore_decl; 32 | 33 | extern tmp_store_struct tmp_store; 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /lp_solve_4.0/lpsolve.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kevinlb1/CATS/38cbf35f5c36796522cb76895fd6388f0dd63f5c/lp_solve_4.0/lpsolve.rc -------------------------------------------------------------------------------- /lp_solve_4.0/mps2lp.c: -------------------------------------------------------------------------------- 1 | #include "lpkit.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) { 5 | lprec *lp; 6 | FILE *fpin, *fpout; 7 | int i; 8 | 9 | for (i = 1; i < argc; i++) 10 | if (argv[i][0] == '-') { 11 | printf("mps to lp file converter\n"); 12 | printf("Usage: mps2lp [inputfile.mps [outputfile.lp]] [outputfile.lp]\n"); 13 | return (1); 14 | } 15 | 16 | if (argc >= 2) { 17 | fpin = fopen(argv[1], "r"); 18 | if (fpin == NULL) { 19 | fprintf(stderr, "Unable to open input file %s\n", argv[1]); 20 | return (2); 21 | } 22 | } else 23 | fpin = stdin; 24 | 25 | if (argc >= 3) { 26 | fpout = fopen(argv[2], "w"); 27 | if (fpout == NULL) { 28 | fprintf(stderr, "Unable to open output file %s\n", argv[2]); 29 | return (3); 30 | } 31 | } else 32 | fpout = stdout; 33 | 34 | fprintf(stderr, "reading mps file\n"); 35 | lp = read_mps(fpin, FALSE); 36 | if (fpin != stdin) 37 | fclose(fpin); 38 | 39 | if (lp == NULL) { 40 | fprintf(stderr, "Unable to read mps file\n"); 41 | return (4); 42 | } else { 43 | fprintf(stderr, "writing lp file\n"); 44 | if (!write_LP(lp, fpout)) { 45 | fprintf(stderr, "Unable to write lp file\n"); 46 | return (5); 47 | } 48 | } 49 | if (fpout != stdout) 50 | fclose(fpout); 51 | 52 | return (0); 53 | } 54 | -------------------------------------------------------------------------------- /lp_solve_4.0/patchlevel.h: -------------------------------------------------------------------------------- 1 | #ifndef __PATCHLEVEL_H__ 2 | #define __PATCHLEVEL_H__ 3 | 4 | #define MAJORVERSION 4 5 | #define MINORVERSION 0 6 | #define RELEASE 1 7 | #define BUILD 0 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /lp_solve_4.0/read.h: -------------------------------------------------------------------------------- 1 | /* prototypes of functions used in the parser */ 2 | 3 | #ifndef __READ_H__ 4 | #define __READ_H__ 5 | 6 | int init_read(void); 7 | int add_constraint_name(char *name, int row); 8 | void store_re_op(void); 9 | void null_tmp_store(void); 10 | int store_bounds(void); 11 | void add_int_var(char *name); 12 | void rhs_store(REAL value); 13 | int var_store(char *var, int row, REAL value); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /lp_solve_4.0/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Developer Studio generated include file. 3 | // Used by lpsolve.rc 4 | // 5 | 6 | // Next default values for new objects 7 | // 8 | #ifdef APSTUDIO_INVOKED 9 | #ifndef APSTUDIO_READONLY_SYMBOLS 10 | #define _APS_NEXT_RESOURCE_VALUE 101 11 | #define _APS_NEXT_COMMAND_VALUE 40001 12 | #define _APS_NEXT_CONTROL_VALUE 1000 13 | #define _APS_NEXT_SYMED_VALUE 101 14 | #endif 15 | #endif 16 | -------------------------------------------------------------------------------- /lp_solve_4.0/ufortify.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FILE: 3 | * ufortify.h 4 | * 5 | * DESCRIPTION: 6 | * User options for fortify. Changes to this file require fortify.c to be 7 | * recompiled, but nothing else. 8 | */ 9 | 10 | #ifndef __UFORTIFY_H__ 11 | #define __UFORTIFY_H__ 12 | 13 | #define FORTIFY_STORAGE 14 | 15 | #if defined MSDOS || defined __BORLANDC__ || defined __HIGHC__ 16 | #define KNOWS_POINTER_TYPE 17 | #endif 18 | 19 | #define FORTIFY_WAIT_FOR_KEY /* Pause after message */ 20 | 21 | #if !defined FORTIFY_BEFORE_SIZE 22 | #define FORTIFY_BEFORE_SIZE 16 /* Bytes to allocate before block */ 23 | #endif 24 | 25 | #if !defined FORTIFY_BEFORE_VALUE 26 | #define FORTIFY_BEFORE_VALUE 0xA3 /* Fill value before block */ 27 | #endif 28 | 29 | #if !defined FORTIFY_AFTER_SIZE 30 | #define FORTIFY_AFTER_SIZE 16 /* Bytes to allocate after block */ 31 | #endif 32 | 33 | #if !defined FORTIFY_AFTER_VALUE 34 | #define FORTIFY_AFTER_VALUE 0xA5 /* Fill value after block */ 35 | #endif 36 | 37 | #define FILL_ON_MALLOC /* Nuke out malloc'd memory */ 38 | 39 | #if !defined FILL_ON_MALLOC_VALUE 40 | #define FILL_ON_MALLOC_VALUE 0xA7 /* Value to initialize with */ 41 | #endif 42 | 43 | #define FILL_ON_FREE /* free'd memory is cleared */ 44 | 45 | #if !defined FILL_ON_FREE_VALUE 46 | #define FILL_ON_FREE_VALUE 0xA9 /* Value to de-initialize with */ 47 | #endif 48 | 49 | #define FORTIFY_CheckInterval 1 /* seconds */ 50 | /* #define CHECK_ALL_MEMORY_ON_MALLOC */ 51 | #define CHECK_ALL_MEMORY_ON_FREE 52 | #define PARANOID_FREE 53 | 54 | #define WARN_ON_MALLOC_FAIL /* A debug is issued on a failed malloc */ 55 | #define WARN_ON_ZERO_MALLOC /* A debug is issued on a malloc(0) */ 56 | #define WARN_ON_FALSE_FAIL /* See Fortify_SetMallocFailRate */ 57 | #define WARN_ON_SIZE_T_OVERFLOW/* Watch for breaking the 64K limit in */ 58 | /* some braindead architectures... */ 59 | 60 | #define FORTIFY_LOCK() 61 | #define FORTIFY_UNLOCK() 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /lp_solve_4.0/windll.def: -------------------------------------------------------------------------------- 1 | DESCRIPTION lpsolve 2 | EXPORTS 3 | lp_solve_version=_lp_solve_version 4 | set_magic=_set_magic 5 | make_lp=_make_lp 6 | read_LP=_read_LP 7 | delete_lp=_delete_lp 8 | copy_lp=_copy_lp 9 | set_mat=_set_mat 10 | set_obj_fn=_set_obj_fn 11 | str_set_obj_fn=_str_set_obj_fn 12 | add_constraint=_add_constraint 13 | str_add_constraint=_str_add_constraint 14 | del_constraint=_del_constraint 15 | add_lag_con=_add_lag_con 16 | str_add_lag_con=_str_add_lag_con 17 | add_column=_add_column 18 | str_add_column=_str_add_column 19 | del_column=_del_column 20 | set_upbo=_set_upbo 21 | set_lowbo=_set_lowbo 22 | set_uprange=_set_uprange 23 | set_lowrange=_set_lowrange 24 | set_int=_set_int 25 | is_int=_is_int 26 | set_semicont=_set_semicont 27 | is_semicont=_is_semicont 28 | set_verbose=_set_verbose 29 | get_verbose=_get_verbose 30 | set_timeout=_set_timeout 31 | get_timeout=_get_timeout 32 | set_print_duals=_set_print_duals 33 | is_print_duals=_is_print_duals 34 | set_print_sol=_set_print_sol 35 | is_print_sol=_is_print_sol 36 | set_debug=_set_debug 37 | is_debug=_is_debug 38 | set_print_at_invert=_set_print_at_invert 39 | is_print_at_invert=_is_print_at_invert 40 | set_trace=_set_trace 41 | is_trace=_is_trace 42 | set_anti_degen=_set_anti_degen 43 | is_anti_degen=_is_anti_degen 44 | set_do_presolve=_set_do_presolve 45 | is_do_presolve=_is_do_presolve 46 | set_max_num_inv=_set_max_num_inv 47 | get_max_num_inv=_get_max_num_inv 48 | set_bb_rule=_set_bb_rule 49 | get_bb_rule=_get_bb_rule 50 | set_obj_bound=_set_obj_bound 51 | get_obj_bound=_get_obj_bound 52 | set_floor_first=_set_floor_first 53 | get_floor_first=_get_floor_first 54 | set_infinite=_set_infinite 55 | get_infinite=_get_infinite 56 | set_epsilon=_set_epsilon 57 | get_epsilon=_get_epsilon 58 | set_epsb=_set_epsb 59 | get_epsb=_get_epsb 60 | set_epsd=_set_epsd 61 | get_epsd=_get_epsd 62 | set_epsel=_set_epsel 63 | get_epsel=_get_epsel 64 | set_scalemode=_set_scalemode 65 | get_scalemode=_get_scalemode 66 | set_improve=_set_improve 67 | is_improve=_is_improve 68 | set_lag_trace=_set_lag_trace 69 | is_lag_trace=_is_lag_trace 70 | set_piv_rule=_set_piv_rule 71 | get_piv_rule=_get_piv_rule 72 | set_break_at_first=_set_break_at_first 73 | is_break_at_first=_is_break_at_first 74 | set_bb_floorfirst=_set_bb_floorfirst 75 | is_bb_floorfirst=_is_bb_floorfirst 76 | set_break_at_value=_set_break_at_value 77 | get_break_at_value=_get_break_at_value 78 | set_negrange=_set_negrange 79 | get_negrange=_get_negrange 80 | set_epsperturb=_set_epsperturb 81 | get_epsperturb=_get_epsperturb 82 | set_epspivot=_set_epspivot 83 | get_epspivot=_get_epspivot 84 | get_max_level=_get_max_level 85 | get_total_nodes=_get_total_nodes 86 | get_total_iter=_get_total_iter 87 | get_objective=_get_objective 88 | get_variables=_get_variables 89 | get_constraints=_get_constraints 90 | add_SOS=_add_SOS 91 | is_SOS_var=_is_SOS_var 92 | set_lp_name=_set_lp_name 93 | set_rh=_set_rh 94 | get_rh=_get_rh 95 | set_rh_vec=_set_rh_vec 96 | str_set_rh_vec=_str_set_rh_vec 97 | set_rh_range=_set_rh_range 98 | get_rh_range=_get_rh_range 99 | set_maxim=_set_maxim 100 | set_minim=_set_minim 101 | set_constr_type=_set_constr_type 102 | get_constr_type=_get_constr_type 103 | set_row_name=_set_row_name 104 | get_row_name=_get_row_name 105 | set_col_name=_set_col_name 106 | get_col_name=_get_col_name 107 | auto_scale=_auto_scale 108 | scale=_scale 109 | scaleCR=_scaleCR 110 | unscale=_unscale 111 | set_basis=_set_basis 112 | get_basis=_get_basis 113 | solve=_solve 114 | lag_solve=_lag_solve 115 | reset_basis=_reset_basis 116 | mat_elm=_mat_elm 117 | get_row=_get_row 118 | get_column=_get_column 119 | get_reduced_costs=_get_reduced_costs 120 | get_sensitivity_obj=_get_sensitivity_obj 121 | get_sensitivity_rhs=_get_sensitivity_rhs 122 | get_Nrows=_get_Nrows 123 | get_Ncolumns=_get_Ncolumns 124 | is_feasible=_is_feasible 125 | column_in_lp=_column_in_lp 126 | read_MPS=_read_MPS 127 | write_mps=_write_mps 128 | write_lp=_write_lp 129 | print_file=_print_file 130 | print_str=_print_str 131 | print_lp=_print_lp 132 | print_objective=_print_objective 133 | print_solution=_print_solution 134 | print_constraints=_print_constraints 135 | print_duals=_print_duals 136 | print_scales=_print_scales 137 | lasterror=_lasterror 138 | put_abortfunc=_put_abortfunc 139 | put_logfunc=_put_logfunc 140 | put_msgfunc=_put_msgfunc 141 | Fortify_EnterScope=__Fortify_EnterScope 142 | Fortify_LeaveScope=__Fortify_LeaveScope 143 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | // remember doing NORMAL for all these sampled Parameters 2 | #include 3 | 4 | // main file for all distributions 5 | #include "BidSet.h" 6 | #include "Param.h" 7 | #include "Legacy.h" 8 | #include "regions.h" 9 | #include "arbitrary.h" 10 | #include "scheduling.h" 11 | #include "matching.h" 12 | #include "paths.h" 13 | #include "featureCalc.h" 14 | 15 | #define MAX(X, Y) ((X) > (Y) ? (X) : (Y)) 16 | 17 | void chooseDistribution(Param &p, Distribution *&d, int argc, char **argv) 18 | { 19 | if (p.dist_weight != NULL) { 20 | double choiceVal = Param::DRand(0, 1.0); 21 | p.distribution = (Param::dist_type) 0; 22 | choiceVal -= p.dist_weight[(int) p.distribution]; 23 | 24 | while (choiceVal > 0) { 25 | p.distribution = Param::dist_type(p.distribution + 1); 26 | assert(p.distribution < Param::UNASSIGNED); 27 | choiceVal -= p.dist_weight[(int) p.distribution]; 28 | } 29 | } 30 | 31 | switch (p.distribution) { 32 | case Param::ARBITRARY: 33 | case Param::ARBITRARY_NPV: 34 | case Param::ARBITRARY_UPV: 35 | d = new Arbitrary(p, argv, argc); 36 | break; 37 | 38 | case Param::MATCHING: 39 | d = new Matching(p, argv, argc); 40 | break; 41 | 42 | case Param::PATHS: 43 | d = new Paths(p, argv, argc); 44 | break; 45 | 46 | case Param::REGIONS: 47 | case Param::REGIONS_NPV: 48 | case Param::REGIONS_UPV: 49 | d = new Regions(p, argv, argc); 50 | break; 51 | 52 | case Param::SCHEDULING: 53 | d = new Scheduling(p, argv, argc); 54 | break; 55 | 56 | case Param::L1: 57 | case Param::L2: 58 | case Param::L3: 59 | case Param::L4: 60 | case Param::L5: 61 | case Param::L6: 62 | case Param::L7: 63 | case Param::L8: 64 | d = new Legacy(p, argv, argc); 65 | break; 66 | 67 | default: 68 | assert(false); // shouldn't be possible- but lets keep the compiler happy! 69 | } 70 | 71 | for (int i = 0; i < argc; i++) { 72 | if (!p.argRecognized[i]) { 73 | printf("Error: unknown parameter %s\n", argv[i]); 74 | exit(1); 75 | } 76 | } 77 | 78 | if (p.random_parameters || p.param_dists[p.distribution]) { 79 | d->randomizeParams(p); 80 | } 81 | } 82 | 83 | int main(int argc, char *argv[]) 84 | { 85 | // parse parameters 86 | Param p(argv, argc); 87 | if (p.parse_error) { 88 | return 1; 89 | } 90 | 91 | if (p.converting) { 92 | BidSet temp(p.filename); 93 | temp.writeCPLEXFile(p); 94 | return (0); 95 | } 96 | 97 | if (p.calculating) { 98 | FeatureCalc f; 99 | BidSet temp(p.filename); 100 | f.calcFeatures(temp); 101 | f.writeFeatures(p.feat_filename); 102 | f.writeFeatNames("featurenames"); 103 | return 0; 104 | } 105 | 106 | Distribution *d; 107 | FeatureCalc f; 108 | 109 | /* 110 | fprintf(stdout, "LEMAN:\n"); 111 | p.feat_polys[2]->print(); 112 | fprintf(stdout, "=======================================\n"); 113 | */ 114 | 115 | //cout.flush(); 116 | 117 | for (int t = 0; t < p.num_runs; t++) { 118 | if (p.random_bids) { 119 | p.num_bids = Param::LRand(p.min_bids, p.max_bids); 120 | } 121 | 122 | if (p.random_goods) { 123 | p.num_goods = Param::LRand(p.min_goods, p.max_goods); 124 | } 125 | 126 | BidSet *b; 127 | 128 | if (p.num_feat_polys) { // generate according to distribution 129 | // generate samples from estimate 130 | Distribution **dists = new Distribution*[p.numWeightedSamples]; 131 | BidSet **samples = new BidSet*[p.numWeightedSamples]; 132 | double *scores = new double[p.numWeightedSamples]; 133 | Param::dist_type* distTypes = new Param::dist_type[p.numWeightedSamples]; 134 | double sumSquaredUnweightedScore = 0; 135 | double totalScore = 0; 136 | 137 | for (int sampleNum = 0; sampleNum < p.numWeightedSamples; sampleNum++) { 138 | /* 139 | fprintf(stdout, "LEMAN %d:\n", sampleNum); 140 | p.feat_polys[2]->print(); 141 | fprintf(stdout, "=======================================\n"); 142 | */ 143 | chooseDistribution(p, d, argc, argv); 144 | 145 | // produce bids 146 | BidSet *sample = d->generate(p); 147 | 148 | // make integer prices 149 | if (p.integer_prices) { 150 | for (int t = 0; t < sample->numBids(); t++) { 151 | sample->getBid(t)->amount = Param::Round(p.bid_alpha * sample->getBid(t)->amount); 152 | } 153 | } 154 | 155 | f.calcFeatures(*sample); 156 | 157 | /* 158 | fprintf(stderr, "####### FEATS: "); 159 | for(int i=0; ievalAt(f.featureVals); 173 | 174 | for (int i = 1; i < p.num_feat_polys; i++) { 175 | double nextScore = p.feat_polys[i]->evalAt(f.featureVals); 176 | 177 | if (nextScore < unweightedScore) { 178 | unweightedScore = nextScore; 179 | // == fprintf(stderr, "##### NEXT %g\n", nextScore); 180 | } 181 | } 182 | 183 | unweightedScore = MAX(unweightedScore, 0); 184 | // == fprintf(stderr, "####### Score: %g\n", unweightedScore); 185 | sumSquaredUnweightedScore += sqr(unweightedScore); 186 | 187 | double factor = (p.dist_weight ? p.dist_weight[(int) p.distribution] : 1.0); 188 | scores[sampleNum] = unweightedScore / (d->probOfParams * factor); 189 | totalScore += scores[sampleNum]; 190 | 191 | dists[sampleNum] = d; 192 | samples[sampleNum] = sample; 193 | distTypes[sampleNum] = p.distribution; 194 | } 195 | 196 | // NOTE this might be modified to stop when sum reaches 197 | // a certain point instead of the same # of samples every time 198 | /* 199 | if (sumSquaredUnweightedScore < 3) { 200 | printf("Warning: sum squared unweighted scores low in sampling from polynomial-defined distribution: %f\n", sumSquaredUnweightedScore); 201 | } 202 | */ 203 | 204 | double draw = Param::DRand(0.0, totalScore); 205 | int selectedIndex = -1; 206 | 207 | do { 208 | assert(selectedIndex + 1 < p.numWeightedSamples); 209 | draw -= scores[++selectedIndex]; 210 | } 211 | while (draw > 0); 212 | 213 | // == fprintf(stderr, "####### Selected %d: %g\n", selectedIndex, scores[selectedIndex]); 214 | d = dists[selectedIndex]; 215 | b = samples[selectedIndex]; 216 | // p.distribution = distTypes[selectedIndex]; 217 | 218 | for (int i = 0; i < p.numWeightedSamples; i++) { 219 | if (i != selectedIndex) { 220 | delete dists[i]; 221 | delete samples[i]; 222 | } 223 | } 224 | 225 | delete[] dists; 226 | delete[] samples; 227 | delete[] scores; 228 | delete[] distTypes; 229 | } 230 | else { 231 | chooseDistribution(p, d, argc, argv); 232 | 233 | // produce bids 234 | b = d->generate(p); 235 | 236 | // make integer prices 237 | if (p.integer_prices) { 238 | for (int t = 0; t < b->numBids(); t++) { 239 | b->getBid(t)->amount = Param::Round(p.bid_alpha * b->getBid(t)->amount); 240 | } 241 | } 242 | } 243 | 244 | // output 245 | if (p.output_parameter_settings) { 246 | printf("CATS running %d of %d....\n\n%s\n%s\n", t + 1, 247 | p.num_runs, p.outputSettings(false), d->outputSettings(false)); 248 | } 249 | 250 | // write CATS output 251 | b->writeOutput(p, d, t); 252 | 253 | // write CPLEX output if desired 254 | if (p.cplex_output) { 255 | b->writeCPLEXFile(p, t); 256 | // printf("Num components in bid graph: %d\n", b->numComponents()); 257 | } 258 | 259 | delete d; 260 | delete b; 261 | } 262 | 263 | return 0; 264 | } 265 | 266 | -------------------------------------------------------------------------------- /matching.h: -------------------------------------------------------------------------------- 1 | #ifndef _MATCHING_H 2 | #define _MATCHING_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "bid.h" 10 | #include "BidSet.h" 11 | #include "Distribution.h" 12 | 13 | #define sqr(x) ((x)*(x)) 14 | #define max(x,y) (((x) > (y)) ? (x) : (y)) 15 | #define min(x,y) (((x) < (y)) ? (x) : (y)) 16 | 17 | class Matching : public Distribution { 18 | public: 19 | // constructor 20 | Matching(Param &p, char * argv [], int argc); 21 | 22 | // destructor 23 | ~Matching(); 24 | 25 | // generate the bidset 26 | BidSet *generate(Param &p); 27 | void randomizeParams(Param &p); 28 | 29 | // output command-line usage 30 | static void usage(); 31 | 32 | // output distribution parameters, either to the screen or to a file 33 | char *outputSettings(bool tofile); 34 | 35 | protected: 36 | // constants 37 | static const int MAX_LONGEST_FLIGHT_LENGTH; // = 10 38 | static const int Z_MAX_DEV; // = 10 39 | static const int NUMCITIES; // = 4 40 | 41 | // parameters 42 | int m_max_airport_price; 43 | int m_early_takeoff_deviation; 44 | int m_late_takeoff_deviation; 45 | int m_early_land_deviation; 46 | int m_late_land_deviation; 47 | double m_deviation; 48 | double m_delay_coeff; 49 | double m_amount_late_coeff; 50 | 51 | // locals 52 | int num_times; 53 | 54 | typedef struct { 55 | double x, y; 56 | } point; 57 | 58 | point *cities; 59 | double **edges; 60 | double *cost; 61 | double max_l; 62 | char *output_buffer; 63 | 64 | // helper functions 65 | inline double longestFlightLength(double x) { 66 | return min(MAX_LONGEST_FLIGHT_LENGTH, x - 1); 67 | } 68 | 69 | // compute the L2 distance between two cities 70 | inline double RealDistance(int city1, int city2) { 71 | return sqrt(sqr(cities[city2].x - cities[city1].x) + 72 | sqr(cities[city2].y - cities[city1].y)); 73 | } 74 | 75 | // initialize the cities. 76 | // regardless of the number of goods, there are only 4 cities, wich are the real 77 | // ones used in the FAA application 78 | 79 | void SetupCities(); 80 | }; 81 | 82 | #endif // _MATCHING_H 83 | 84 | -------------------------------------------------------------------------------- /normal.cpp: -------------------------------------------------------------------------------- 1 | /*************************************************************** 2 | * Return (0,1) normally distributed random variable 3 | * (C) Numerical Recipes in C 4 | * 5 | ***************************************************************/ 6 | 7 | #include 8 | #include 9 | #include "normal.h" 10 | 11 | Normal::Normal(Param &p) 12 | { 13 | x1[0] = (unsigned short) (p.random_seed >> 16); 14 | x1[1] = (unsigned short) (p.random_seed & 0xFFFF); 15 | x1[2] = (unsigned short) (0x330E); 16 | 17 | x2[0] = (unsigned short) (p.random_seed2 >> 16); 18 | x2[1] = (unsigned short) (p.random_seed2 & 0xFFFF); 19 | x2[2] = (unsigned short) (0x330E); 20 | } 21 | 22 | Normal::Normal(long seed1, long seed2) 23 | { 24 | x1[0] = (unsigned short) (seed1 >> 16); 25 | x1[1] = (unsigned short) (seed1 & 0xFFFF); 26 | x1[2] = (unsigned short) (0x330E); 27 | 28 | x2[0] = (unsigned short) (seed2 >> 16); 29 | x2[1] = (unsigned short) (seed2 & 0xFFFF); 30 | x2[2] = (unsigned short) (0x330E); 31 | } 32 | 33 | Normal::~Normal() {} 34 | 35 | double Normal::gaussdev(int reset) 36 | { 37 | static int iset = 0; 38 | static double gset = 0; 39 | double fac, rsq, v1, v2; 40 | 41 | if (reset) { 42 | iset = 0; /*reinit*/ 43 | } 44 | 45 | if (iset == 0) { 46 | do { 47 | v1 = 2.0 * Param::ERand(x1) - 1.0; 48 | v2 = 2.0 * Param::ERand(x2) - 1.0; 49 | 50 | rsq = v1 * v1 + v2 * v2; 51 | } 52 | while (rsq >= 1.0 || rsq == 0.0); 53 | 54 | fac = sqrt(-2.0 * log(rsq) / rsq); 55 | // printf("VS: %lf\t%lf\t%lf\t%lf\n", v1, v2, rsq, fac);*/ 56 | gset = v1 * fac; 57 | iset = 1; 58 | return v2 * fac; 59 | } 60 | else { 61 | iset = 0; 62 | return gset; 63 | } 64 | } 65 | 66 | double Normal::draw(double mu, double sigma) 67 | { 68 | return gaussdev(0) * sigma + mu; 69 | } 70 | 71 | -------------------------------------------------------------------------------- /normal.h: -------------------------------------------------------------------------------- 1 | /*Declarations for normal number generator*/ 2 | 3 | #ifndef _NORMAL_H_ 4 | #define _NORMAL_H_ 5 | 6 | #include "Param.h" 7 | 8 | class Normal { 9 | public: 10 | Normal(Param &p); 11 | Normal(long seed1, long seed2); 12 | ~Normal(); 13 | 14 | double draw(double mu, double sigma); 15 | 16 | private: 17 | double gaussdev(int); 18 | unsigned short x1[3], x2[3]; 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /obj/Makefile: -------------------------------------------------------------------------------- 1 | VPATH = .. 2 | 3 | all : ${OBJ}# DO NOT DELETE 4 | # DO NOT DELETE 5 | 6 | testPoly.o: polyModel.h 7 | arbitrary.o: Distribution.h Param.h polyModel.h regions.h normal.h bid.h 8 | arbitrary.o: BidSet.h arbitrary.h 9 | bid.o: bid.h 10 | BidSet.o: BidSet.h bid.h Param.h polyModel.h Distribution.h 11 | Distribution.o: Distribution.h Param.h polyModel.h 12 | featureCalc.o: featureCalc.h BidSet.h bid.h Param.h polyModel.h 13 | featureCalc.o: Distribution.h 14 | Legacy.o: Legacy.h bid.h normal.h Param.h polyModel.h BidSet.h Distribution.h 15 | main.o: BidSet.h bid.h Param.h polyModel.h Distribution.h Legacy.h normal.h 16 | main.o: regions.h arbitrary.h scheduling.h matching.h paths.h featureCalc.h 17 | matching.o: bid.h BidSet.h Param.h polyModel.h Distribution.h matching.h 18 | normal.o: normal.h Param.h polyModel.h 19 | Param.o: Param.h polyModel.h Legacy.h bid.h normal.h BidSet.h Distribution.h 20 | Param.o: featureCalc.h 21 | paths.o: Param.h polyModel.h Distribution.h bid.h BidSet.h paths.h 22 | polyModel.o: polyModel.h Param.h 23 | regions.o: normal.h Param.h polyModel.h bid.h BidSet.h Distribution.h 24 | regions.o: regions.h 25 | scheduling.o: Distribution.h Param.h polyModel.h BidSet.h bid.h scheduling.h 26 | -------------------------------------------------------------------------------- /paths.h: -------------------------------------------------------------------------------- 1 | #ifndef _PATHS_H 2 | #define _PATHS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Param.h" 10 | #include "Distribution.h" 11 | #include "bid.h" 12 | #include "BidSet.h" 13 | //#include "normal.h" 14 | 15 | #define max(x,y) (((x) > (y)) ? (x) : (y)) 16 | #define sqr(x) ((x)*(x)) 17 | 18 | class Paths : public Distribution { 19 | public: 20 | // constructor 21 | Paths(Param &p, char *argv[], int argc); 22 | 23 | // destructor 24 | virtual ~Paths(); 25 | 26 | static void usage(); 27 | BidSet *generate(Param &p); 28 | void randomizeParams(Param &p); 29 | 30 | protected: 31 | // constants 32 | static const int Z_MAX_BID_SET_SIZE; // = 100 33 | static const int Z_NUMBIDS; // = 20000 34 | static const double INF; // = 500000.0 35 | 36 | // parameters 37 | int maxCities; 38 | int initialNumCities; 39 | int initial_connections; 40 | double edge_density; 41 | double building_penalty; 42 | double shipping_cost_factor; 43 | int max_bid_set_size; 44 | 45 | // FOR NORMAL CITY PLACEMENT 46 | // CityPlacementType city_placement_type; 47 | // double cluster_std_dev; 48 | // int num_clusters; 49 | 50 | bool keepDisconnected; 51 | bool countUnusedEdges; 52 | double goodError; 53 | bool display_graph; 54 | int numcities; 55 | 56 | // local structs 57 | struct DistanceTo { 58 | int city; 59 | double distance; 60 | }; 61 | 62 | struct Path { 63 | int * pathArr, pathlen; 64 | double cost; 65 | 66 | Path(int maxCities) { 67 | pathArr = new int[maxCities]; 68 | } 69 | 70 | Path(const Path &orig, int maxCities) { 71 | pathlen = orig.pathlen; 72 | cost = orig.cost; 73 | pathArr = new int[maxCities]; 74 | 75 | for (int i = 0; i < pathlen; i++) { 76 | pathArr[i] = orig.pathArr[i]; 77 | } 78 | } 79 | 80 | ~Path() { 81 | delete[] pathArr; 82 | } 83 | }; 84 | 85 | char *output_buffer; 86 | 87 | struct Point { 88 | double x, y; 89 | }; 90 | 91 | Point * cities; 92 | double ** edges; 93 | // edges is a matrix representing the distance between cities 94 | // 0 means unknown, neg means known, but no direct connection 95 | // pos means known with direct connection 96 | 97 | int ** edgesgood; 98 | int *goodedges1; 99 | int *goodedges2; 100 | int **adjacentTo; 101 | int *numAdjacentTo; 102 | int *q, *pi; 103 | double *d; 104 | 105 | Path **best_paths; 106 | int num_best_paths; 107 | double maxcost; 108 | BidSet *bids; 109 | int num_edges; 110 | 111 | // Normal *norm; 112 | // helper functions 113 | 114 | // L2 distance between the two cities caching of already computed values 115 | inline double RealDistance(int city1, int city2) { 116 | if (!edges[city1][city2]) { 117 | edges[city1][city2] = edges[city2][city1] = -sqrt(sqr(cities[city2].x - cities[city1].x) + 118 | sqr(cities[city2].y - cities[city1].y)); 119 | } 120 | 121 | return fabs(edges[city1][city2]); 122 | } 123 | 124 | // distance between two points taking into account building penalty if the cities aren't connected 125 | inline double BuildingDistance(int u, int v) { 126 | return (RealDistance(u, v) * building_penalty); 127 | } 128 | 129 | void DisplayGraph(char * edgefile, char * cityfile); 130 | void DisplayBid(char * edgefile, Bid b); 131 | void Relax(int u, int v, double w, double d[]); 132 | int ExtractMin(int q[], int &qsize, double d[]); 133 | void ConstructPath(int s, int t); 134 | void InitGraph(); 135 | bool Build(int city1, int city2); 136 | void BuildShortEdges(); 137 | bool BuildViaPaths(); 138 | void BuildSmallWorldEdges(); 139 | int BuildEdgeGoodList(); 140 | void BuildGraph(int num_goods); 141 | void BidOnPath(Path &p); 142 | void FindBids(Path &p, int dest); 143 | bool generateBids(Param &p, BidSet *bids); 144 | inline bool isConnected(); 145 | int numComponents(); 146 | char *outputSettings(bool to_file); 147 | static double param_mins[]; 148 | static double param_maxs[]; 149 | }; 150 | 151 | #endif // _PATHS_H 152 | 153 | -------------------------------------------------------------------------------- /polyModel.cpp: -------------------------------------------------------------------------------- 1 | #include "polyModel.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | // #ifdef LINUX 12 | // #include 13 | // #else 14 | // #include 15 | // #endif 16 | 17 | #include "Param.h" 18 | 19 | const int PolyModel::EMPTY = -1; 20 | 21 | PolyModel::PolyModel(const char *fname) 22 | { 23 | filename = new char[strlen(fname) + 1]; 24 | strcpy(filename, fname); 25 | 26 | minimumKnown = false; 27 | argMin = NULL; 28 | 29 | std::ifstream coeffFile(filename); 30 | 31 | if (!coeffFile) { 32 | printf("Could not open coefficient file \"%s\".\n", filename); 33 | exit(1); 34 | } 35 | 36 | // == fprintf(stderr, "OPENED: %s\n", filename); 37 | coeffFile >> degree; 38 | 39 | if (degree < 1) { 40 | printf("Invalid number of degrees (%d) specified in coefficient file \"%s\".\n", numVars, filename); 41 | exit(1); 42 | } 43 | 44 | coeffFile >> numVars; 45 | 46 | if (numVars < 1) { 47 | printf("Invalid number of parameters (%d) specified in coefficient file \"%s\".\n", 48 | numVars, filename); 49 | exit(1); 50 | } 51 | 52 | numFreeVars = numVars; 53 | numCoeffs = simplicalNK(degree, numVars + 1); 54 | coeffs = new double[numCoeffs]; 55 | varIsFree = new bool[numVars]; 56 | 57 | for (int i = 0; i < numVars; i++) { 58 | varIsFree[i] = true; 59 | } 60 | 61 | isConstant = true; 62 | 63 | // read coeffs 64 | for (int i = 0; i < numCoeffs; i++) { 65 | if (coeffFile.eof()) { 66 | printf("Too few coefficients (%d) in file \"%s\". Expected %d.\n", i, filename, numCoeffs); 67 | exit(1); 68 | } 69 | 70 | coeffFile >> coeffs[i]; 71 | 72 | if (i > 0 && coeffs[i] != 0) { 73 | isConstant = false; 74 | } 75 | 76 | // eat whitespace 77 | char next; 78 | while (coeffFile.get(next)) { 79 | if (!isspace(next)) { 80 | coeffFile.putback(next); 81 | break; 82 | } 83 | } 84 | } 85 | 86 | if (!coeffFile.eof()) { 87 | printf("Too many coefficients specified in file \"%s\". Expected %d.\n", filename, numCoeffs); 88 | exit(1); 89 | } 90 | } 91 | 92 | PolyModel::PolyModel(const PolyModel &orig) 93 | { 94 | degree = orig.degree; 95 | numVars = orig.numVars; 96 | numFreeVars = orig.numFreeVars; 97 | 98 | filename = new char[strlen(orig.filename) + 1]; 99 | strcpy(filename, orig.filename); 100 | 101 | numCoeffs = orig.numCoeffs; 102 | coeffs = new double[numCoeffs]; 103 | varIsFree = new bool[numVars]; 104 | 105 | for (int i = 0; i < numCoeffs; i++) { 106 | coeffs[i] = orig.coeffs[i]; 107 | } 108 | 109 | for (int i = 0; i < numVars; i++) { 110 | varIsFree[i] = orig.varIsFree[i]; 111 | } 112 | 113 | minimumKnown = orig.minimumKnown; 114 | minimum = orig.minimum; 115 | 116 | if (orig.argMin) { 117 | argMin = new double[numVars]; 118 | 119 | for (int i = 0; i < numVars; i++) { 120 | argMin[i] = orig.argMin[i]; 121 | } 122 | } 123 | else { 124 | argMin = NULL; 125 | } 126 | } 127 | 128 | PolyModel::~PolyModel() 129 | { 130 | delete[] coeffs; 131 | delete[] varIsFree; 132 | delete[] filename; 133 | 134 | if (argMin) { 135 | delete[] argMin; 136 | } 137 | } 138 | 139 | double PolyModel::evalAt(double pos[]) 140 | { 141 | int vars[degree]; 142 | 143 | for (int i = 0; i < degree; i++) { 144 | vars[i] = EMPTY; 145 | } 146 | 147 | double answer = 0; 148 | 149 | do { 150 | double val = coeffOf(vars); 151 | 152 | for (int i = 0; i < degree && vars[i] != EMPTY; i++) { 153 | val *= pos[vars[i]]; 154 | } 155 | 156 | answer += val; 157 | } 158 | while (increment(vars)); 159 | 160 | return answer; 161 | } 162 | 163 | double PolyModel::derivAt(double pos[], int var) 164 | { 165 | int vars[degree]; 166 | 167 | for (int i = 0; i < degree; i++) { 168 | vars[i] = EMPTY; 169 | } 170 | 171 | double answer = 0; 172 | 173 | do { 174 | int varDegree = 0; 175 | 176 | for (int i = 0; i < degree; i++) { 177 | if (vars[i] == var) { 178 | varDegree++; 179 | } 180 | else if (vars[i] < var) { 181 | break; 182 | } 183 | } 184 | 185 | if (varDegree == 0) { 186 | continue; 187 | } 188 | 189 | double derivOfTerm = coeffOf(vars) * varDegree; 190 | 191 | for (int i = 0; i < degree && vars[i] != EMPTY; i++) { 192 | // skips first instance of var, which has been "derivated out" 193 | if (vars[i] != var || (i != 0 && vars[i - 1] == var)) { 194 | derivOfTerm *= pos[vars[i]]; 195 | } 196 | } 197 | 198 | answer += derivOfTerm; 199 | } 200 | while (increment(vars)); 201 | 202 | return answer; 203 | } 204 | 205 | double PolyModel::indefIntegralAt(int var, double value) 206 | { 207 | // bad things happen if this function is misused... 208 | assert(numFreeVars == 1); 209 | 210 | for (int i = 0; i < numVars; i++) { 211 | if (i == var) { 212 | assert(varIsFree[i] == true); 213 | } 214 | else { 215 | assert(varIsFree[i] == false); 216 | } 217 | } 218 | 219 | int vars[degree]; 220 | 221 | for (int i = 0; i < degree; i++) { 222 | vars[i] = EMPTY; 223 | } 224 | 225 | double answer = 0; 226 | 227 | for (int i = 0; i <= degree; i++) { 228 | answer += coeffOf(vars) * pow(value, i + 1) / (i + 1); 229 | 230 | if (i < degree) { 231 | vars[i] = var; 232 | } 233 | } 234 | 235 | return answer; 236 | } 237 | 238 | // returns next term in poly 239 | bool PolyModel::increment(int *vars) 240 | { 241 | int lowestFreeVar = 0, highestFreeVar = numVars - 1; 242 | 243 | while (!varIsFree[lowestFreeVar]) { 244 | if (lowestFreeVar == numVars - 1) { 245 | return false; 246 | } 247 | else { 248 | lowestFreeVar++; 249 | } 250 | } 251 | 252 | while (!varIsFree[highestFreeVar]) { 253 | highestFreeVar--; 254 | } 255 | 256 | int pos = degree - 1; 257 | 258 | while (vars[pos] == EMPTY && pos > 0) { 259 | pos--; 260 | } 261 | 262 | if (pos == 0) { 263 | if (vars[pos] == EMPTY) { 264 | vars[pos] = lowestFreeVar; 265 | return true; 266 | } 267 | } 268 | else { 269 | while (pos > 0 && vars[pos - 1] == vars[pos]) 270 | pos--; 271 | } 272 | 273 | if (pos == 0 && vars[pos] == highestFreeVar) { 274 | while (pos < degree && vars[pos] != EMPTY) { 275 | vars[pos++] = lowestFreeVar; 276 | } 277 | 278 | if (pos == degree) { 279 | return false; 280 | } 281 | else { 282 | vars[pos] = lowestFreeVar; 283 | } 284 | } 285 | else { 286 | vars[pos]++; 287 | 288 | if (vars[pos] > highestFreeVar) { 289 | return false; 290 | } 291 | else { 292 | while (!varIsFree[vars[pos]]) { 293 | vars[pos]++; 294 | } 295 | } 296 | 297 | while (++pos < degree && vars[pos] != EMPTY) { 298 | vars[pos] = lowestFreeVar; 299 | } 300 | } 301 | 302 | return true; 303 | } 304 | 305 | int PolyModel::indexOf(int *vars) 306 | { 307 | int lastEmpty = degree; 308 | int lastVar = EMPTY; 309 | int index = 0; 310 | 311 | for (int pos = degree - 1; pos >= 0; pos--) { 312 | assert(vars[pos] >= lastVar); 313 | 314 | if (vars[pos] == EMPTY) { 315 | continue; 316 | } 317 | 318 | if (lastVar == EMPTY) { 319 | lastEmpty = pos + 1; 320 | index += simplicalNK(pos, numVars + 1); 321 | } 322 | 323 | index += simplicalNK(lastEmpty - pos, vars[pos]); 324 | lastVar = vars[pos]; 325 | } 326 | 327 | return index; 328 | } 329 | 330 | double &PolyModel::coeffOf(int *vars) 331 | { 332 | return coeffs[indexOf(vars)]; 333 | } 334 | 335 | double PolyModel::constantTerm() 336 | { 337 | return coeffs[0]; 338 | } 339 | 340 | void PolyModel::integrateOut(int var, double min, double max) 341 | { 342 | assert(var < numVars && var >= 0); 343 | assert(varIsFree[var] == true); 344 | 345 | int vars[degree]; 346 | 347 | for (int i = 0; i < degree; i++) { 348 | vars[i] = EMPTY; 349 | } 350 | 351 | double oldCoeffs[numCoeffs]; 352 | 353 | for (int i = 0; i < numCoeffs; i++) { 354 | oldCoeffs[i] = coeffs[i]; 355 | coeffs[i] = 0; 356 | } 357 | 358 | do { 359 | int varDegree = 0; 360 | int integratedTerm[degree]; 361 | 362 | for (int i = 0; i < degree; i++) { 363 | if (vars[i] == var) { 364 | varDegree++; 365 | } 366 | else { 367 | integratedTerm[i - varDegree] = vars[i]; 368 | } 369 | } 370 | 371 | for (int i = degree - varDegree; i < degree; i++) { 372 | integratedTerm[i] = EMPTY; 373 | } 374 | 375 | coeffOf(integratedTerm) += 376 | (oldCoeffs[indexOf(vars)] / (varDegree + 1)) * (pow(max, varDegree + 1) - pow(min, 377 | varDegree + 1)); 378 | } 379 | while (increment(vars)); 380 | 381 | varIsFree[var] = false; 382 | numFreeVars--; 383 | } 384 | 385 | void PolyModel::instantiate(int var, double value) 386 | { 387 | assert(var < numVars && var >= 0); 388 | assert(varIsFree[var] == true); 389 | 390 | int vars[degree]; 391 | 392 | for (int i = 0; i < degree; i++) { 393 | vars[i] = EMPTY; 394 | } 395 | 396 | double oldCoeffs[numCoeffs]; 397 | 398 | for (int i = 0; i < numCoeffs; i++) { 399 | oldCoeffs[i] = coeffs[i]; 400 | coeffs[i] = 0; 401 | } 402 | 403 | do { 404 | int varDegree = 0; 405 | int instantiatedTerm[degree]; 406 | 407 | for (int i = 0; i < degree; i++) { 408 | if (vars[i] == var) { 409 | varDegree++; 410 | } 411 | else { 412 | instantiatedTerm[i - varDegree] = vars[i]; 413 | } 414 | } 415 | 416 | for (int i = degree - varDegree; i < degree; i++) { 417 | instantiatedTerm[i] = EMPTY; 418 | } 419 | 420 | coeffOf(instantiatedTerm) += oldCoeffs[indexOf(vars)] * pow(value, varDegree); 421 | } 422 | while (increment(vars)); 423 | 424 | varIsFree[var] = false; 425 | numFreeVars--; 426 | } 427 | 428 | void PolyModel::multiplyBy(double constant) 429 | { 430 | for (int i = 0; i < numCoeffs; i++) { 431 | coeffs[i] *= constant; 432 | } 433 | } 434 | 435 | void PolyModel::add(double constant) 436 | { 437 | coeffs[0] += constant; 438 | } 439 | 440 | void PolyModel::findMinimum(double mins[], double maxs[]) 441 | { 442 | const double learnRate = 0.001; 443 | const int numRestarts = 50; 444 | 445 | double *width = new double[numVars]; 446 | 447 | for (int i = 0; i < numVars; i++) { 448 | assert(mins[i] <= maxs[i]); 449 | width[i] = maxs[i] - mins[i]; 450 | } 451 | 452 | double *pos = new double[numVars]; 453 | double *step = new double[numVars]; 454 | double valAtPos; 455 | 456 | argMin = new double[numVars]; 457 | double lowestVal; 458 | bool lowestValValid = false; 459 | 460 | for (int i = 0; i < numRestarts; i++) { 461 | for (int j = 0; j < numVars; j++) { 462 | pos[j] = Param::DRand(mins[j], maxs[j]); 463 | } 464 | 465 | valAtPos = evalAt(pos); 466 | 467 | bool done = false; 468 | 469 | while (!done) { 470 | for (int j = 0; j < numVars; j++) { 471 | step[j] = -(derivAt(pos, j) * learnRate * width[j]); 472 | } 473 | 474 | for (int j = 0; j < numVars; j++) { 475 | pos[j] += step[j]; 476 | 477 | if (pos[j] < mins[j]) { 478 | pos[j] = mins[j]; 479 | } 480 | else if (pos[j] > maxs[j]) { 481 | pos[j] = maxs[j]; 482 | } 483 | } 484 | 485 | double valAtLastPos = valAtPos; 486 | valAtPos = evalAt(pos); 487 | 488 | if (valAtPos >= valAtLastPos) { 489 | done = true; 490 | } 491 | } 492 | 493 | if (!lowestValValid || valAtPos < lowestVal) { 494 | for (int j = 0; j < numVars; j++) { 495 | argMin[j] = pos[j]; 496 | } 497 | 498 | lowestVal = valAtPos; 499 | lowestValValid = true; 500 | } 501 | } 502 | 503 | minimumKnown = true; 504 | minimum = lowestVal; 505 | 506 | delete[] width; 507 | delete[] pos; 508 | delete[] step; 509 | } 510 | 511 | int PolyModel::nChooseK(int n, int k) 512 | { 513 | int result = 1; 514 | 515 | for (int i = k + 1; i <= n; i++) { 516 | result *= i; 517 | } 518 | 519 | for (int i = 1; i <= (n - k); i++) { 520 | result /= i; 521 | } 522 | 523 | return result; 524 | } 525 | 526 | inline int PolyModel::simplicalNK(int n, int k) 527 | { 528 | if (n == 0) { 529 | return 1; 530 | } 531 | else if (k == 0) { 532 | return 0; 533 | } 534 | else { 535 | return nChooseK(n + k - 1, k - 1); 536 | } 537 | } 538 | 539 | void PolyModel::print() 540 | { 541 | int vars[degree]; 542 | 543 | for (int i = 0; i < degree; i++) { 544 | vars[i] = EMPTY; 545 | } 546 | 547 | do { 548 | for (int i = 0; i < degree; i++) { 549 | if (vars[i] != EMPTY) { 550 | printf("%d", vars[i]); 551 | } 552 | else { 553 | break; 554 | } 555 | } 556 | 557 | printf(":\t"); 558 | printf("%f\n", coeffOf(vars)); 559 | } 560 | while (increment(vars)); 561 | } 562 | 563 | void PolyModel::testIncrement() 564 | { 565 | int *vars = new int[degree]; 566 | 567 | for (int i = 0; i < degree; i++) { 568 | vars[i] = EMPTY; 569 | } 570 | 571 | while (increment(vars)) { 572 | for (int i = 0; i < degree; i++) { 573 | if (vars[i] != EMPTY) { 574 | printf("%d", vars[i]); 575 | } 576 | } 577 | 578 | printf(": %d\n", indexOf(vars)); 579 | } 580 | } 581 | 582 | -------------------------------------------------------------------------------- /polyModel.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUAD_POLY_H 2 | #define _QUAD_POLY_H 3 | 4 | class PolyModel { 5 | public: 6 | static const int EMPTY; 7 | 8 | int degree; 9 | int numVars; 10 | int numFreeVars; 11 | int numCoeffs; 12 | 13 | double *argMin; 14 | double minimum; 15 | bool minimumKnown; 16 | bool isConstant; 17 | 18 | char *filename; 19 | 20 | private: 21 | double *coeffs; 22 | bool *varIsFree; 23 | 24 | public: 25 | PolyModel(const char* filename); 26 | PolyModel(const PolyModel &orig); 27 | ~PolyModel(); 28 | 29 | double evalAt(double pos[]); 30 | double derivAt(double pos[], int var); 31 | double indefIntegralAt(int var, double val); 32 | 33 | int indexOf(int *vars); 34 | double &coeffOf(int *vars); 35 | double constantTerm(); 36 | 37 | void integrateOut(int var, double min, double max); 38 | void instantiate(int var, double value); 39 | 40 | void multiplyBy(double constant); 41 | void add(double constant); 42 | 43 | void findMinimum(double mins[], double maxs[]); 44 | 45 | void print(); 46 | void testIncrement(); 47 | 48 | private: 49 | int nChooseK(int n, int k); 50 | int simplicalNK(int n, int k); 51 | bool increment(int *vars); 52 | }; 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /qpstuff/L2-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 1 3 | 0.133769 4 | 0.419979 5 | -0.161827 6 | -------------------------------------------------------------------------------- /qpstuff/L3-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | 3.57592 4 | 0.00503666 -0.212696 5 | -0.00161314 6 | 0.0194021 0.108705 7 | -------------------------------------------------------------------------------- /qpstuff/L4-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -8.99881 4 | 21.103 -1.29641 5 | -8.43791 6 | 2.06 0.183332 7 | -------------------------------------------------------------------------------- /qpstuff/L6-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | -0.711014 4 | -1.31219 0.391198 5 | 1.03375 6 | -0.134348 -0.0668684 7 | -------------------------------------------------------------------------------- /qpstuff/L7-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 2 3 | 3.73956 4 | -23.9449 0.272101 5 | 40.8477 6 | -0.454511 -0.131096 7 | -------------------------------------------------------------------------------- /qpstuff/arbitrary-npv-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 6 3 | -17.7561 4 | 0.452206 4.05692 -0.89121 51.287 0.684598 -0.100257 5 | -0.0152703 6 | 0.149891 -5.26993 7 | 0.00674845 0.982692 0.117825 8 | -0.340938 -4.07003 0.906665 -31.046 9 | 0.0235675 0.372127 0.053379 -1.7856 0.150331 10 | -0.000329258 0.00400761 -0.00467413 0.127071 0.00436548 -0.000151092 11 | -------------------------------------------------------------------------------- /qpstuff/arbitrary-upv-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 6 3 | -20.2796 4 | 0.443503 1.09646 1.98182 56.8352 2.94199 -4.02222 5 | -0.00912043 6 | -0.117709 0.959382 7 | -0.0854517 1.39009 -0.59459 8 | -0.296057 -2.3414 -1.52283 -34.1379 9 | -0.0254594 -0.703291 -0.364767 -3.33883 -0.224239 10 | -0.00211959 1.07527 -0.130499 3.86936 0.36119 0.545454 11 | -------------------------------------------------------------------------------- /qpstuff/cass-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 32 3 | 8004.61 4 | -0.0452937 -0.0604808 0.259629 140046 -362.073 -150.808 5.74601 -5.3063 -11.1784 -53.2446 -2.0661 -18.933 -428.305 1482.47 -67.1643 376.189 -19.0464 69.8381 177.968 -10039.6 9.99422e+06 -239899 7.59109e+06 2481.92 -1515.97 449.476 694.645 -2543.73 50077.4 -1.18087 15538 -578.576 5 | -2.92069e-09 6 | 5.3639e-08 -4.84005e-07 7 | 6.78115e-08 2.20583e-06 -6.06892e-07 8 | 0.0580182 10.113 -1.71078 214091 9 | 0.000221154 -0.00677607 -0.000732066 -3327.92 6.8277 10 | 3.64483e-06 0.00052051 8.61965e-05 -1490.1 4.31663 0.035681 11 | -2.5049e-05 -0.000603996 0.000233649 495.086 -0.816703 -0.0474301 0.00790035 12 | -2.30857e-05 -0.000724011 0.000285838 -39.3719 -0.333428 -0.282391 0.110093 -0.00959845 13 | 0.00010071 0.0156327 -0.00233376 805.245 -0.639504 -0.590113 0.177236 0.220058 0.067925 14 | 0.000424065 0.0359892 -0.00796817 -523.119 0.109225 1.64493 -0.212444 -0.14062 -1.15394 -2.31105 15 | -6.7865e-05 -0.00201601 0.000847418 57.1767 0.120358 -0.278593 0.0204823 -0.0641722 0.572169 0.627822 -0.0778965 16 | 0.000155668 0.0150001 -0.00322123 5964.94 -4.75901 0.23088 -0.394189 -0.242706 3.02953 -1.66302 0.250672 -0.245871 17 | -0.000785074 -0.112988 0.0184105 -8191.91 4.48406 4.15687 0.600388 0.309787 -5.94224 2.35322 -3.21032 -14.4544 39.0085 18 | 0.000107263 0.00208338 -0.000699297 3140.08 -17.5955 -7.36797 -0.010423 0.00102214 6.84169 8.12654 -1.367 3.54077 -37.3159 0.681588 19 | 5.94963e-05 0.00473112 -0.00105386 975.501 0.403949 1.04391 -0.0121656 0.0321808 -0.0391391 -0.531005 0.688148 0.279785 -4.59038 2.78823 -0.337926 20 | 0.000427798 0.0128711 -0.00458961 3661.04 4.11643 -4.35798 -1.8921 -0.15497 0.0427026 7.92509 -0.0927814 4.64234 -18.1527 0.193225 1.0171 -0.850229 21 | -0.00014876 -0.0028338 0.00140672 88.6434 -0.946922 -0.327689 0.0761909 0.0255642 -0.303527 0.175147 -0.100799 -0.64356 2.02414 3.16393 0.0173645 -2.71873 0.242499 22 | -4.40055e-05 0.000603404 0.000210949 1017.95 -3.28342 -0.689823 -0.0236511 0.12794 0.0706839 0.0326547 0.0355802 -0.285127 0.3007 4.19181 -0.305555 -1.75083 0.230426 0.222443 23 | -7.32942e-05 -0.00113996 0.000647281 1291 -4.56968 -1.47426 0.187948 -0.026151 -0.0379823 0.269832 -0.0501928 -0.0943726 -2.20507 7.95662 -0.729962 1.71934 0.0983439 1.34772 0.712791 24 | -0.0322036 -0.964816 0.329997 -1.86266e+06 418.921 -52.0749 -14.3657 35.4897 323.993 416.697 37.398 -684.29 -2759.22 468.092 26.8896 660.064 -303.466 -126.134 -438.922 -1816.02 25 | 32.5835 967.862 -332.185 -5.35016e+08 1.97564e+06 53472.6 14412.6 -36436.4 -323273 -419541 -38175.7 684746 2.74511e+06 -442346 -28387.9 -640251 307711 125921 440930 3.96692e+06 -2.15144e+09 26 | 0.472429 21.006 -6.01216 2.2043e+07 5838.46 -210.557 106.672 -313.897 -2455.02 -3935.12 -337.365 7980.24 13821.8 -661.187 -621.79 -1791.09 1334.91 1145.76 3076.66 130833 -1.69393e+08 -989449 27 | -15.0468 -665.151 190.799 -1.75247e+08 -705026 5968.7 -3299.03 10347.6 78047.1 124515 10871.2 -253062 -431864 14676.8 19754.3 50035.8 -44413 -35446.6 -98306.6 -3.72375e+06 4.94373e+09 6.36514e+07 -1.02353e+09 28 | -0.00379891 -0.0763101 0.0534345 -4813.99 -107.353 152.206 -26.5199 -1.45128 -38.0516 119.619 -0.151438 68.7276 -172.561 -66.7257 56.6164 107.625 169.141 -55.1175 14.862 27110.4 -2.70858e+07 -76464.6 2.41497e+06 432.112 29 | 0.00230968 0.0156971 -0.0171493 -12817.8 77.5769 -19.1498 1.12605 -2.88364 9.04481 -52.384 -3.47364 -34.1334 259.884 -227.781 10.3862 165.873 -49.8639 3.47313 -22.3942 844.468 -839745 -14300.5 448921 255.709 7.55668 30 | -0.00172598 -0.0114799 0.00676706 116215 -145.576 -8.39131 0.738466 -0.500085 -28.7167 16.5347 -1.40223 19.9751 8.74401 261.743 -16.7951 -2.50664 21.7702 -10.225 19.1236 1698.92 -1.69792e+06 -47252.7 1.49245e+06 314.09 -6.96144 -59.6377 31 | 0.00377218 0.0341376 -0.0235546 -126263 137.797 31.9221 -3.37776 8.77637 43.8279 59.4873 3.23534 3.7709 -132.596 -275.513 52.8998 -182.718 5.02017 2.06911 -22.5498 -4420.25 4.40146e+06 137828 -4.34412e+06 -1864.8 -31.5196 173.987 -106.8 32 | 0.00868528 0.0204961 -0.0273373 -156121 219.286 -33.4748 -4.2971 -30.0484 89.4978 7.8544 -16.6969 33.0161 -170.655 -519.518 34.68 92.2564 -29.0662 -1.33939 -12.9664 10428.4 -1.03962e+07 -247667 7.81504e+06 2727.14 -31.2998 139.321 -1.29467 -120.859 33 | 0.0203301 -0.216304 -0.00509666 -179519 93.7432 287.612 37.8794 -41.491 -60.6483 -851.913 101.537 347.095 -837.067 -595.101 -367.58 473.146 238.969 28.7854 -165.424 10190.8 -9.99213e+06 -134521 4.15427e+06 7692.09 1292.96 -760.925 -630.208 1051.42 9247.59 34 | 2.27856e-08 4.57561e-05 -2.73185e-05 2.92954 -0.00275843 -0.00225979 -0.000151542 9.72952e-05 -0.00175277 -0.00139545 -0.000113949 0.374905 0.435579 -0.110084 -0.0207407 0.000257781 -0.00382416 0.00325807 0.000415733 1.97615 -1984.51 -33.1035 1049.8 -0.143408 -0.0057472 0.000646688 0.00399319 -0.00705484 -0.0499191 2.65979e-08 35 | 0.0370746 0.19973 -0.245831 180231 -308.89 -188.787 -41.1192 196.565 48.1309 1240.03 -118.954 86.0859 2684.74 -1702.88 55.8742 -3747.79 -207.491 -32.3758 264.399 4201.36 -4.36408e+06 -20453.6 726262 -5074.22 -71.7381 481.144 -286.739 3873.61 -24584.7 -54037.6 -16613.1 36 | 0.0413523 0.323096 -0.618151 -358758 872.329 -175.853 -27.8929 -88.4617 -1407.06 -125.061 -36.7996 -432.629 5168.2 2032.88 264.652 2418.57 -98.8428 -265.945 -71.4406 3500.1 -3.59922e+06 401027 -1.26411e+07 -3539.61 1785.4 -466.369 -1920.55 3511.11 16468.6 -0.0621697 -8867.61 -21640.4 37 | -------------------------------------------------------------------------------- /qpstuff/cplex-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 32 3 | 30018.2 4 | -0.456649 -5.95013 3.73255 -831181 1183.8 680.961 5.96986 235.272 -3143.91 849.338 241.969 960.797 10792.7 1394.46 -531.55 -2007.16 -199.939 379.966 -761.988 -81771.9 8.06559e+07 -239674 8.22174e+06 -41986 -17582.8 3727.58 11542 11611.6 -1.74654e+06 -2.09453 286960 278431 5 | -1.50924e-08 6 | 1.55145e-06 3.10094e-05 7 | 3.87631e-07 -7.89268e-06 -3.3975e-06 8 | -0.312187 -54.0317 8.30659 2.21624e+06 9 | 0.000263981 -0.0270737 0.00216168 -6067.67 18.1031 10 | -0.000183702 0.0130669 0.00129492 3071.99 -2.12704 -4.97897 11 | -7.58826e-05 0.00197295 -4.83455e-05 447.875 -4.06054 1.94803 -0.00334851 12 | -0.000165978 -0.00311083 0.00199893 -190.64 0.331239 -0.272584 0.262782 -0.0803059 13 | -8.64442e-05 -0.00422411 0.0012352 1167.43 11.4585 -6.15669 -0.0127101 -1.32992 -0.106056 14 | 0.000254136 0.0172735 -0.00497968 -5360.81 3.58658 3.40888 -0.413966 0.303307 -3.61134 1.10855 15 | 0.000111671 -0.00159123 -0.000896264 544.914 -0.164483 0.306843 -0.227646 0.10324 1.37842 -0.540375 0.0887521 16 | 0.000826982 0.00827559 -0.00877061 -14294 10.413 4.15997 0.527311 -0.324238 -16.2236 -2.83214 -0.204456 -1.01873 17 | -0.0036156 -0.184728 0.0530142 -3385.75 -48.7548 15.5196 2.77792 5.34723 1.81165 18.5673 -4.42066 68.3326 -18.7153 18 | 0.00583376 0.348324 -0.0930796 2526.27 -17.0287 11.085 -2.25839 1.89164 14.7106 -5.56961 -3.65844 3.82328 -54.9555 -10.1087 19 | -0.000345652 -0.0275086 0.00690629 -1098.61 9.42427 -2.61081 0.490474 -0.860476 -1.69487 -0.908701 1.51577 -1.92114 10.7789 -4.42828 -0.354887 20 | 0.00306584 0.198217 -0.0498992 2299.36 -10.0514 0.441087 -0.452314 1.24504 -1.68516 -5.00994 -1.03554 3.1212 8.00779 -4.75398 -3.23581 -3.51442 21 | 0.000739994 0.0440083 -0.0111959 3799.24 -19.2291 -6.16816 2.59843 -0.243783 -3.72643 2.00685 -0.182101 4.85124 9.26572 4.18952 -3.03342 1.00093 2.99615 22 | -0.000263345 0.00779412 0.00156479 -1415.76 -4.03617 3.32229 -0.394518 0.26812 -1.62596 -0.651649 -0.40327 0.420089 12.0287 5.15141 -2.1561 3.92955 3.72925 -0.896994 23 | -8.14969e-05 0.0231237 -0.00257422 -21.6291 -6.16958 0.612876 1.25834 -0.688061 -6.87465 -1.04339 0.242472 -1.82301 24.6648 12.2458 -4.23518 7.18513 5.44975 2.68509 -0.454708 24 | 0.0498831 -0.215432 -0.453358 -2.28272e+06 -1542.97 1587.74 -157.489 71.2943 2336.02 -1041.74 -47.1183 2147.82 -5960.91 -1174.26 694.658 -255.66 746.363 -295.211 -346.549 -46892.5 25 | -45.9981 285.756 405.909 -1.192e+09 5.01491e+06 -1.53465e+06 157182 -67677.9 -2.2834e+06 933680 44858.2 -2.16157e+06 5.77995e+06 1.11536e+06 -687180 329926 -732056 287147 350574 9.64476e+07 -4.95604e+10 26 | 0.279365 23.1758 -5.4401 2.56171e+07 14210.5 -3142.41 666.531 30.36 -10744.1 1162.57 189.191 -15412.2 19676.4 -2253.46 -2829.67 2376.49 -1843.15 699.8 2125.38 864729 -8.58159e+08 -2.98095e+06 27 | -11.1677 -773.203 201.105 -2.19382e+08 -1.02953e+06 65475.8 -21588.2 -3632.2 316825 570.408 -4323.41 492664 -577484 106502 90570.1 -84402.8 46751.8 -18886 -66859.5 -2.9449e+07 2.92446e+10 2.0404e+08 -3.47203e+09 28 | 0.183856 2.81318 -2.22921 -798732 -122.958 1637.64 88.5087 153.636 1146.85 -1766.51 -106.288 -409.243 -888.67 -1481.57 -326.623 -242.231 625.547 -45.39 -85.9156 51670.5 -5.1791e+07 -1.00818e+06 3.17528e+07 53515.1 29 | 0.0182802 0.242951 -0.166506 248036 -198.842 109.05 12.9507 -14.9164 167.15 17.7505 -58.0309 -194.731 1112.78 -658.769 -85.7795 869.31 134.327 -184.348 -25.531 -6314.87 6.22075e+06 -60225.5 2.01959e+06 -16394.8 294.659 30 | 0.00571858 0.257931 -0.106795 544267 -591.853 255.965 -24.3773 12.3134 -15.0064 -579.009 115.974 -252.505 -11.5812 -801.991 220.669 477.798 123.699 -41.9355 -36.5737 -11936.6 1.18268e+07 341897 -1.07587e+07 -6330.29 -934.318 -235.826 31 | -0.0465982 -0.643946 0.423703 -611498 652.911 -385.241 15.3728 -19.527 -414.824 680.177 -152.847 357.644 503.453 914.089 -113.882 -934.194 -304.945 238.559 67.7277 21059.6 -2.08316e+07 -97822 2.92177e+06 17848.3 565.905 596.46 -752.085 32 | -0.0206567 -0.644464 0.265582 -1.47479e+06 2281.64 -266.084 73.2943 199.342 -453.283 1271.92 -64.785 -187.265 3833.3 2718.92 -934.231 -2482.58 -283.591 -324.758 -319.609 134230 -1.34606e+08 -2.73638e+06 8.66002e+07 9451.95 3806.93 1532.43 -3231.95 4088.13 33 | 1.1006 9.8953 -7.26332 1.86045e+06 -4023.1 53.0885 110.402 -647.778 12346.4 -5194.32 184.625 -3897.23 -46319.1 2004.62 337.377 5761.2 2434.8 -1432.98 1761.62 -117146 1.20925e+08 1.18711e+06 -3.87428e+07 51109.8 19697.7 -7270.42 10389.7 -70201.8 278937 34 | -3.87992e-05 -0.000247164 0.000196315 2.81923 -0.00798267 0.0153719 -0.00334814 0.00346652 0.00862426 -0.00395249 -0.00394519 -7.32732 0.759614 0.668303 -0.0543828 0.107013 -0.0124242 0.0158727 -0.000451894 60.0457 -60361.5 -975.386 30971.3 -9.09194 0.0122521 0.010959 -0.0621345 0.106213 0.274755 -1.01217e-07 35 | -0.836224 -6.51078 5.31172 -2.28077e+06 6372.49 -1473.41 -322.082 890.988 -7945.21 7083.75 -424.066 3594.34 31780.6 -8112.14 1612.74 -9193.61 -4485 1857.43 -2669.28 581191 -5.82726e+08 -5.01527e+06 1.58114e+08 170080 -7289.3 18561.9 -22919.1 -49779.7 -431665 1.433e+06 467628 36 | 0.49892 6.89596 -5.94253 -510576 487.126 -1491.07 30.4777 -445.551 -5319.34 510.39 -0.673821 2131.55 20731.1 671.056 -1208.46 -1044.72 72.9295 82.7503 311.992 269183 -2.72731e+08 371858 -9.90059e+06 -192080 12165.6 -7014.53 -33619.5 100469 60638.5 -1.69533 -488244 -294002 37 | -------------------------------------------------------------------------------- /qpstuff/lehman-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 32 3 | -10875.1 4 | 0.0318627 0.255989 -0.179693 467694 -296.652 114.208 30.726 37.3205 657.823 -155.111 56.7959 252.464 -772.943 -1983.02 -176.373 366.99 -30.6841 -76.537 -156.996 -48461.9 4.84757e+07 397339 -1.24764e+07 -2543.08 -1561.95 1306.9 1992.68 -918.072 487126 3.13101 37311.2 51882.7 5 | 1.08622e-08 6 | 1.31449e-06 1.4048e-05 7 | -3.24835e-07 -1.43332e-05 2.13793e-06 8 | -0.268546 -20.7895 4.6504 -478147 9 | -0.000115625 0.00578466 0.0004332 792.535 -2.86958 10 | 0.000153092 0.0102604 -0.00193035 1298.79 -4.78434 -0.485943 11 | 1.60909e-05 0.000708594 -0.000287238 -164.178 0.475585 0.599078 -0.034904 12 | -1.05708e-05 0.000479796 6.98159e-05 -36.0667 -0.322198 0.0160992 0.0606232 0.0151661 13 | -7.30713e-05 -0.00617757 0.00162353 -992.093 -0.167568 2.30985 -0.0102327 -0.0636123 -0.114843 14 | -2.53731e-05 -0.00777746 0.000651904 -145.239 1.92244 0.401057 0.0423002 0.0336774 -0.594612 -1.27104 15 | -4.33861e-05 -0.00163332 0.000675496 -105.569 -0.156158 0.110741 -0.00603945 -0.0220683 0.321047 0.449096 -0.0231283 16 | 0.000550713 0.0129925 -0.00778074 -4627.56 4.39484 1.18612 0.0833675 -0.0326319 -8.29542 -1.29299 -0.0388905 -0.214785 17 | 0.000228164 0.0163119 -0.00471761 4535.42 -6.67269 -15.5392 1.48119 0.189342 0.713046 7.24163 -1.70879 34.3911 -2.05057 18 | 0.000465197 0.0242089 -0.00730931 688.868 4.1505 7.10096 -2.30168 0.56602 5.98535 -2.65191 -0.748977 -1.74681 -18.0701 -3.16121 19 | -2.84576e-05 -0.00645633 0.00125086 62.5929 1.35162 -0.363398 0.130371 -0.0186532 -0.399315 -0.662677 0.37968 -0.0929345 1.78415 0.368129 -0.404617 20 | 0.00044757 0.0180871 -0.00625917 2531.67 4.63762 2.7919 -1.49355 -0.606669 6.93751 -1.7042 -0.382958 -0.520076 -26.6139 0.866025 -1.07925 2.49096 21 | 0.000198325 0.00864937 -0.00272745 -20.4721 0.52403 0.749291 0.121154 0.0728815 -0.446511 -0.468772 0.166259 0.478748 1.72338 -0.927449 -0.610642 -1.95591 0.104971 22 | 5.43242e-05 0.0036318 -0.000867849 -15.1829 1.57485 1.09101 -0.129598 0.0188623 0.523931 -0.965531 -0.0350335 -0.0866058 0.221199 -1.12256 -0.337323 -0.935923 -0.317885 -0.0389962 23 | 3.94925e-05 0.000828579 -0.000571489 -452.042 3.21219 1.22482 -0.336653 0.0739774 -1.0228 -0.11973 -0.116546 -0.258024 7.3899 -1.3861 -0.570493 -1.52682 -0.310354 -0.958354 -0.577737 24 | 0.014742 0.563375 -0.243216 1.47429e+06 -394.537 -143.278 47.1546 -17.425 499.892 -322.808 26.1212 91.5412 -1533.38 438.113 -75.5283 237.6 -170.516 223.104 10.7784 -5809.58 25 | -14.912 -566.693 243.661 -2.46331e+08 -825706 144368 -46732.1 17694.2 -507810 312845 -24815.1 -96797 1.57162e+06 -417479 73375 -237855 168223 -229663 -10959 1.28405e+07 -7.03003e+09 26 | -0.215053 -12.5656 3.57292 2.98441e+07 11870.8 1815.11 -366.115 215.837 -3759.18 738.86 81.3066 -1628.95 10447.6 -2610.09 281.501 -1327.96 1011.69 -1561.3 -352.551 206201 -1.94231e+08 -610137 27 | 6.54266 393.614 -109.675 -3.13363e+08 -1.00765e+06 -60358.7 11064.2 -7175.05 123371 -19567.6 -3216.43 51367 -346948 74942.1 -5955.24 39452.5 -32382.4 50944.8 11921.8 -7.38251e+06 7.00302e+09 4.24777e+07 -7.32813e+08 28 | 0.0334797 0.622653 -0.400769 -248137 142.684 110.591 61.9934 6.80197 -131.158 -187.766 17.2714 43.1702 569.438 577.756 -269.963 263.002 40.6771 -13.3965 -35.0593 52107 -5.23728e+07 -568186 1.79828e+07 12156 29 | -0.0034493 -0.107756 0.0494358 -177050 108.964 -74.3575 4.56291 0.185844 -32.6291 -42.0878 1.06285 48.6719 78.9207 222.022 0.859138 -59.8452 -8.92464 20.9848 48.4089 7375.64 -7.40008e+06 -129992 4.1335e+06 -2013.13 121.055 30 | -0.00537412 -0.05216 0.0399548 436417 -537.284 39.8816 -2.66943 8.03759 -40.7298 -8.82857 -7.73807 -12.2651 286.535 145.475 2.32379 2.76215 48.252 22.831 26.7807 -10853 1.08229e+07 237027 -7.48163e+06 -851.675 71.6962 -29.9793 31 | -0.00172195 0.0674118 0.0027695 -358329 534.325 -14.4701 -7.95414 -2.75995 77.6141 -2.129 23.7976 33.6797 -1009.93 660.756 35.5012 -8.22728 -50.8701 -39.1413 -66.3905 8512.86 -8.34755e+06 -170008 5.2768e+06 6188.59 49.2656 -70.7389 146.352 32 | 0.00543942 0.136848 -0.091329 -674112 857.44 -39.7382 19.1011 -28.7566 19.4804 -28.4577 -15.3027 -47.9995 52.4116 715.617 -195.034 144.501 -70.0739 11.5518 -125.006 5639.63 -5.89798e+06 -63806.5 2.16883e+06 -13798.2 -509.366 261.884 -569.758 1129.06 33 | 0.0202868 0.691481 -0.738465 -818717 362.107 343.596 -25.7768 -117.792 -1445.29 298.608 -354.185 -1164.31 4928.85 -1107.15 331.781 -554.957 173.964 45.5697 358.324 39485 -4.07084e+07 -663681 2.17074e+07 -51454.8 523.802 -685.466 -4863.26 4316.83 20663.4 34 | -2.65021e-05 -0.000452641 0.000308215 2.46897 -1.22243e-05 -0.0104873 0.0010619 -0.00122016 -0.00671861 -0.0184672 0.00186452 0.860386 -1.06074 0.325658 0.0467583 0.0271375 -0.00509762 0.00212357 0.00219907 8.47393 -8405.69 -61.7845 1911.94 4.49817 -0.0167705 -0.00867904 0.038125 -0.0566067 -0.256829 7.53573e-08 35 | -0.0112275 -1.35263 0.824145 1.41866e+06 -821.66 -721.27 36.1008 197.484 2414.39 -252.414 596.803 956.401 -10663 2321.42 -180.01 -312.483 -377.121 -30.4264 -280.03 20032.2 -1.85558e+07 224402 -8.00038e+06 93711.1 939.77 -7422.15 6563.97 19722.1 14662.1 -482360 -151454 36 | -0.0612111 -0.621619 0.464965 -754641 300.874 -597.366 47.11 -192.827 -3245.81 115.303 -108.305 471.916 14675.1 88.1897 -624.859 998.83 -46.7805 433.597 152.357 4146.92 -3.84763e+06 466120 -1.5024e+07 -19203.6 874.276 2197.55 2655.83 -16027.1 -83265.8 -0.100828 34899.7 -122313 37 | -------------------------------------------------------------------------------- /qpstuff/matching-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 7 3 | -1.4986 4 | -0.101928 -0.0224545 0.013977 -0.0576487 0.0728071 0.481627 0.041565 5 | 0.00681253 6 | -0.00409065 0.00174781 7 | 0.0132837 0.00227747 -0.00633037 8 | 0.00254566 -0.00183403 -0.000603875 0.00150485 9 | 0.0391607 -0.00158889 -0.00933941 0.0165143 -0.107585 10 | 0.0111576 0.0136514 -0.0460258 0.0307218 -0.0464579 -0.186722 11 | 0.0123194 0.00953396 0.0145642 0.00285844 -0.0826985 -0.0784668 0.0463647 12 | -------------------------------------------------------------------------------- /qpstuff/regions-npv-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 7 3 | -7.23705 4 | 0.0411801 -1.30028 -0.963119 16.1284 -1.05767 2.12002 -0.0572838 5 | -0.0176778 6 | 0.0774161 -0.462207 7 | 0.0861423 2.01032 0.395843 8 | 0.112676 -0.127502 0.249656 -7.08279 9 | 0.288299 3.68464 0.461516 20.0604 -43.005 10 | 0.0116305 -0.381507 0.187148 -3.78712 5.54305 -0.110075 11 | 0.00158176 -0.0560699 -0.00626131 0.0539474 -0.111734 0.00310634 0.000329516 12 | -------------------------------------------------------------------------------- /qpstuff/regions-upv-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 7 3 | -18.0751 4 | 0.541924 -7.53023 2.1959 39.9613 16.5511 5.20869 -3.19005 5 | -0.0184482 6 | 0.0413918 0.438835 7 | -0.00102722 2.3926 0.0122616 8 | -0.344284 2.72608 -1.06812 -19.8256 9 | -0.272394 20.4974 -9.71123 0.0917703 -44.2048 10 | 0.0050217 0.544128 -0.352655 -5.85369 -2.22575 -0.754437 11 | 0.0230663 -0.271661 -1.2493 4.17848 -2.00818 0.131456 -0.182221 12 | -------------------------------------------------------------------------------- /qpstuff/scheduling-qp.txt: -------------------------------------------------------------------------------- 1 | 2 2 | 4 3 | -1.09354 4 | 0.00889166 -0.24318 -0.0638089 -0.125536 5 | -3.2763e-05 6 | 0.000458567 0.0949869 7 | 0.000158018 0.0834924 0.0549782 8 | -0.000961023 0.0970142 0.0477987 0.109137 9 | -------------------------------------------------------------------------------- /regions.h: -------------------------------------------------------------------------------- 1 | // TODO: 2 | // - read in rows and cols as a parameter 3 | 4 | #ifndef _REGIONS_H 5 | #define _REGIONS_H 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "normal.h" 13 | #include "bid.h" 14 | #include "BidSet.h" 15 | 16 | class Regions : public Distribution { 17 | public: 18 | // constructor: parse input 19 | Regions(Param &p, char * argv[], int argc); 20 | virtual ~Regions(); 21 | 22 | // the main function that generates all the bids 23 | BidSet *generate(Param &p); 24 | void randomizeParams(Param &p); 25 | 26 | // output information on how to use the distribution 27 | static void usage(bool arbitrary); 28 | 29 | // output values of all variables related to the distribution 30 | char *outputSettings(bool tofile); 31 | static const int Z_NUMGOODS; // = 500 32 | 33 | protected: 34 | int num_goods; // temp value that stores p->num_goods 35 | 36 | // parameters 37 | 38 | int max_good_value; 39 | int max_substitutible_bids; 40 | double remove_neighbor; 41 | double additional_neighbor; 42 | double additional_location; 43 | double jump_prob; 44 | double additivity; 45 | double deviation; 46 | double budget_factor; 47 | double resale_factor; 48 | double normal_mean; 49 | double normal_stdev; 50 | bool normal_prices; 51 | bool arbitrary; 52 | int effectiveDist; 53 | 54 | // local structs 55 | struct item { 56 | int numneigh; 57 | int arraySize; 58 | int * neighbor; 59 | double c; /* common value */ 60 | double p; /* private value */ 61 | double pn; /* intermediate calculations */ 62 | double *d; /* array for use in "arbitrary" subclass; not used in "regions" */ 63 | 64 | static const int arrayIncSize; // = 5 65 | 66 | item() { 67 | numneigh = 0; 68 | arraySize = 0; 69 | neighbor = NULL; 70 | d = NULL; 71 | } 72 | 73 | ~item() { 74 | if (neighbor) { 75 | delete[] neighbor; 76 | } 77 | if (d) { 78 | delete[] d; 79 | } 80 | } 81 | 82 | void addNeighbor(int n) { 83 | if (numneigh == arraySize) { 84 | int *newNeigh = new int[arraySize += arrayIncSize]; 85 | 86 | if (neighbor) { 87 | for (int i = 0; i < numneigh; i++) { 88 | newNeigh[i] = neighbor[i]; 89 | } 90 | 91 | delete[] neighbor; 92 | } 93 | 94 | neighbor = newNeigh; 95 | } 96 | 97 | neighbor[numneigh++] = n; 98 | } 99 | 100 | }; 101 | 102 | struct bid_type_for_generating { //formerly "B" 103 | int *items; 104 | int num_items; 105 | double c; /* total common value for this bid */ 106 | double value; /* value for this bid */ 107 | 108 | bid_type_for_generating() { 109 | items = new int[Z_NUMGOODS]; 110 | } 111 | 112 | ~bid_type_for_generating() { 113 | delete[] items; 114 | } 115 | }; 116 | 117 | // locals 118 | item *location; 119 | int nrows, ncols; 120 | int numgoods; 121 | char *output_buffer; 122 | Normal *norm; 123 | 124 | // helper functions 125 | inline double S(double x) { 126 | return pow(x, 1 + additivity); 127 | } 128 | 129 | bool IsConnectedLocations(int loc1, int loc2); 130 | void ConnectLocations(int loc1, int loc2); 131 | void Connect(int i, int j, int x, int y); 132 | bool IsConnected(int i, int j, int x, int y); 133 | 134 | // NUMBER OF ROWS AND COLS SHOULD BE READ IN DIRECTLY RATHER THAN NUMBER OF GOODS 135 | // note: this function modifies the number of goods as floor(sqrt(num_goods))**2 136 | // build the real estate map 137 | 138 | virtual int BuildMap(); 139 | void DisplayMap(char *edgefile, char *cityfile); 140 | 141 | // return the value of the bid. This amount is private + common value 142 | double Value(bid_type_for_generating &b); 143 | 144 | // return only the common value of the bid 145 | 146 | double CommonValue(bid_type_for_generating &b); 147 | 148 | int InBidAlready(bid_type_for_generating &b, int new_item); 149 | 150 | // decide how much weight to add if location a and b are in the same bid 151 | 152 | virtual double weightFromLocations(int a, int b); 153 | void Add_Good_to_Bundle(bid_type_for_generating *b); 154 | static int bid_compare(const void *a, const void *b); 155 | Bid *MakeGeneratedBidIntoRealBid(bid_type_for_generating *b); 156 | int Identical(bid_type_for_generating &a, bid_type_for_generating &b); 157 | }; // Object Regions 158 | 159 | #endif // _REGIONS_H 160 | 161 | -------------------------------------------------------------------------------- /scheduling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "Distribution.h" 7 | #include "Param.h" 8 | #include "BidSet.h" 9 | #include "bid.h" 10 | #include "scheduling.h" 11 | 12 | double Scheduling::sched_param_mins[] = {3, 0, 0, -0.2}; 13 | double Scheduling::sched_param_maxs[] = {0, 1.0, 1.0, 1.0}; 14 | 15 | // note sched_param_maxs[0], max_length is set in constructor 16 | // because it depends on number of goods 17 | // create a bid on the range start..end with value val 18 | 19 | Bid *Scheduling::makeBid(int start, int end, double val) 20 | { 21 | Bid *b = new Bid(val); 22 | 23 | for (int i = 0; i <= end - start; i++) { 24 | b->addGood(start + i); 25 | } 26 | 27 | return b; 28 | } 29 | 30 | // generate the bidset 31 | BidSet *Scheduling::generate(Param &p) 32 | { 33 | int l, d_1, cur_max_deadline, new_d, start; 34 | double dev; 35 | BidSet *bids = new BidSet(p.num_goods, p.num_bids); 36 | 37 | // make bids 38 | for (int t = 0; bids->numBids() < p.num_bids; t++) { 39 | // initialize 40 | l = 1 + (Param::LRand() % max_length); 41 | d_1 = l - 1 + Param::LRand() % (p.num_goods - l + 1); 42 | dev = 1 - deviation + 2 * Param::DRand() * deviation; 43 | cur_max_deadline = -1; 44 | new_d = d_1; 45 | 46 | do { 47 | // make a deadline 48 | for (start = 0; start < p.num_goods; start++) { 49 | if ((start + l - 1 <= new_d) && (cur_max_deadline < start + l - 1)) { 50 | bids->addXor(makeBid(start, start + l - 1, dev * pow((double) l, 51 | 1 + additivity) * d_1 / new_d)); 52 | } 53 | } 54 | 55 | cur_max_deadline = new_d; 56 | 57 | if (cur_max_deadline == p.num_goods - 1) { 58 | break; 59 | } 60 | 61 | new_d = cur_max_deadline + 1 + Param::LRand() % (p.num_goods - cur_max_deadline - 1); 62 | } 63 | while (Param::DRand() <= prob_additional_deadline); 64 | 65 | // finish up the bids; refine 66 | bids->doneAddingXor(p.remove_dominated_bids); 67 | 68 | // output progress 69 | if (p.output_parameter_settings && (!(t % p.output_frequency) || bids->numBids() >= p.num_bids)) { 70 | int count = printf("Number of %sbids: %d Number of bidders: %d", 71 | (p.remove_dominated_bids ? "non-dominated " : ""), bids->numBids(), t); 72 | 73 | if (bids->numBids() < p.num_bids) { 74 | for (int counter = 0; counter < count; counter++) { 75 | printf("\b"); 76 | } 77 | } 78 | else { 79 | printf("\n"); 80 | } 81 | } 82 | } 83 | 84 | return bids; 85 | } 86 | 87 | // display usage information 88 | void Scheduling::usage() 89 | { 90 | int count = printf("Usage for Scheduling Distribution:\n"); 91 | 92 | for (int t = 0; t < count; t++) { 93 | printf("="); 94 | } 95 | 96 | printf(" -maxlength : max number of timeslots required by a bidder\n"); 97 | printf(" -deviation : (uniform) deviation in value\n"); 98 | printf(" -prob_add_deadline : probability that an additional deadline will be added\n"); 99 | printf(" -additivity : degree of super/subadditivity in valuations\n"); 100 | } 101 | 102 | // constructor 103 | Scheduling::Scheduling(Param &p, char *argv[], int argc) 104 | { 105 | output_buffer = NULL; 106 | int i; 107 | 108 | // defaults 109 | max_length = 10; 110 | deviation = 0.5; 111 | prob_additional_deadline = 0.7; 112 | additivity = 0.2; 113 | 114 | // parse parameters. Ignore those that don't apply 115 | for (i = 1; i < argc; i++) { 116 | // now read in values 117 | if (argv[i][0] == '-' || argv[i][0] == '/') { 118 | if (!stricmp("-max_length", argv[i])) { 119 | p.argRecognized[i] = true; 120 | 121 | if (i + 1 >= argc) { 122 | usage(); 123 | } 124 | 125 | max_length = atoi(argv[i + 1]); 126 | i++; 127 | p.argRecognized[i] = true; 128 | } 129 | else if (!stricmp("-deviation", argv[i])) { 130 | p.argRecognized[i] = true; 131 | 132 | if (i + 1 >= argc) { 133 | usage(); 134 | } 135 | 136 | deviation = atof(argv[i + 1]); 137 | i++; 138 | p.argRecognized[i] = true; 139 | } 140 | else if (!stricmp("-prob_add_deadline", argv[i])) { 141 | p.argRecognized[i] = true; 142 | 143 | if (i + 1 >= argc) { 144 | usage(); 145 | } 146 | 147 | prob_additional_deadline = atof(argv[i + 1]); 148 | i++; 149 | p.argRecognized[i] = true; 150 | } 151 | else if (!stricmp("-additivity", argv[i])) { 152 | p.argRecognized[i] = true; 153 | 154 | if (i + 1 >= argc) { 155 | usage(); 156 | } 157 | 158 | additivity = atof(argv[i + 1]); 159 | i++; 160 | p.argRecognized[i] = true; 161 | } 162 | } 163 | } 164 | 165 | // this must be set here, because it depends on num_goods 166 | sched_param_maxs[0] = (int) (0.5 * p.num_goods); 167 | } 168 | 169 | void Scheduling::randomizeParams(Param &p) 170 | { 171 | if (p.param_dists[(int) Param::SCHEDULING] != NULL) { 172 | double params[4]; 173 | 174 | randomizeParamsWithDistribution(p.param_dists[(int) Param::SCHEDULING], 4, 175 | sched_param_mins, sched_param_maxs, params, p); 176 | 177 | max_length = (int) params[0]; 178 | deviation = params[1]; 179 | prob_additional_deadline = params[2]; 180 | additivity = params[3]; 181 | } 182 | else { 183 | max_length = Param::LRand((int) sched_param_mins[0], (int) sched_param_maxs[0]); // 10 184 | deviation = Param::DRand(sched_param_mins[1], sched_param_maxs[1]); // 0.5 185 | prob_additional_deadline = Param::DRand(sched_param_mins[2], sched_param_maxs[2]); // 0.7 186 | additivity = Param::DRand(sched_param_mins[3], sched_param_maxs[3]); // 0.2 187 | } 188 | } 189 | 190 | Scheduling::~Scheduling() 191 | { 192 | if (output_buffer) { 193 | delete[] output_buffer; 194 | } 195 | } 196 | 197 | // output values of all variables related to the distribution 198 | char *Scheduling::outputSettings(bool tofile) 199 | { 200 | // allocate variables 201 | char comment[3]; 202 | 203 | if (tofile) { 204 | comment[0] = '%'; 205 | comment[1] = ' '; 206 | comment[2] = 0; 207 | } 208 | else { 209 | comment[0] = 0; 210 | } 211 | 212 | char buffer1[80], buffer2[80], buffer3[80], buffer4[80], buffer5[80]; 213 | 214 | // generate output 215 | sprintf(buffer1, "%sScheduling Distribution Parameters:\n", comment); 216 | sprintf(buffer2, "%smax_length = %d\n", comment, max_length); 217 | sprintf(buffer3, "%sdeviation = %f\n", comment, deviation); 218 | sprintf(buffer4, "%sprob_additional_deadline = %f\n", comment, prob_additional_deadline); 219 | sprintf(buffer5, "%sadditivity = %f\n", comment, additivity); 220 | 221 | // prepare the string and return it 222 | int length = strlen(buffer1) + strlen(buffer2) + strlen(buffer3) + strlen(buffer4) + 223 | strlen(buffer5) + 20; 224 | 225 | if (output_buffer) { 226 | delete[] output_buffer; 227 | } 228 | 229 | output_buffer = new char[length]; 230 | sprintf(output_buffer, "%s%s%s%s%s\n", buffer1, buffer2, buffer3, buffer4, buffer5); 231 | 232 | return output_buffer; 233 | } 234 | 235 | -------------------------------------------------------------------------------- /scheduling.h: -------------------------------------------------------------------------------- 1 | #ifndef _SCHEDULING_H 2 | #define _SCHEDULING_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "Distribution.h" 10 | #include "Param.h" 11 | #include "BidSet.h" 12 | #include "bid.h" 13 | 14 | #define sqr(x) ((x)*(x)) 15 | #define cub(x) ((x)*(x)*(x)) 16 | #define abs(x) ((x) > 0 ? (x) : -(x)) 17 | #define max(x,y) (((x) > (y)) ? (x) : (y)) 18 | #define min(x,y) (((x) < (y)) ? (x) : (y)) 19 | 20 | class Scheduling : public Distribution { 21 | public: 22 | // constructor 23 | Scheduling(Param &p, char *argv[], int argc); 24 | 25 | // destructor 26 | ~Scheduling(); 27 | 28 | // output values of all variables related to the distribution 29 | char *outputSettings(bool tofile); 30 | 31 | // generate the bidset 32 | BidSet *generate(Param &p); 33 | void randomizeParams(Param &p); 34 | 35 | // display usage information 36 | static void usage(); 37 | 38 | protected: 39 | static const double add_low, add_high, 40 | dev_low, dev_high, 41 | prob_low, prob_high; 42 | static int max_len_low, max_len_high; 43 | 44 | // parameters 45 | int max_length; 46 | double deviation; 47 | double prob_additional_deadline; 48 | double additivity; 49 | 50 | // create a bid on the range start... end with value val 51 | Bid *makeBid(int start, int end, double val); 52 | char *output_buffer; 53 | static double sched_param_mins[]; 54 | static double sched_param_maxs[]; 55 | }; 56 | 57 | #endif // _SCHEDULING_H 58 | 59 | -------------------------------------------------------------------------------- /uniform_hybrid: -------------------------------------------------------------------------------- 1 | 0.5 2 | 0.5 3 | 1 4 | 1 5 | 0.5 6 | 0.5 7 | 1 8 | 0 9 | 1 10 | 1 11 | 1 12 | 0 13 | 1 14 | 1 15 | 1 --------------------------------------------------------------------------------