int runLRSBaked(string fName, int numSamples) { srand((unsigned(time(NULL)))); cout << "numSamples: " << numSamples << endl; cout << "Getting gammas..." << endl; int best = INT_MAX; vector<LPEdge> hkSoln = getHKSolutionsBaked(fName, false); vector<ModEdge> graph = xToZ(lpToMod(hkSoln)); vector<double> lambda = getLambdaBaked(fName, graph); weightGraph(graph, lambda); int numNodes = getNumNodes(graph); Graph g = Graph(fName, false); cout << "Done getting gammas" << endl; int numErrs = 0; for (int i = 0; i < numSamples; i++) { int n = numNodes; int cur = getLRSTourFast(graph, lambda, g, n); best = min(cur, best); if (cur == INT_MAX) numErrs++; } cout << "Number of errors: " << numErrs << " out of " << numSamples << " samples" << endl; return best; }
void findWeights(const double *x, const double *knots, double *weights, int numSamples, int splineOrder, int numBins, double rangeLeft, double rangeRight) { int curSample, curBin; double *z = (double*) calloc(numSamples, sizeof(double)); xToZ(x, z, numSamples, splineOrder, numBins, rangeLeft, rangeRight); for (curSample = 0; curSample < numSamples; curSample++) { for (curBin = 0; curBin < numBins; curBin++) { weights[curBin * numSamples + curSample] = basisFunction(curBin, splineOrder, z[curSample], knots, numBins); //printf("%d|%f(%f)\t", curBin, weights[curBin * numSamples + curSample],z[curSample]); } } free(z); }
int runLRS(string fName, int numSamples, bool silent) { srand((unsigned(time(NULL)))); cout << "numSamples: " << numSamples << endl; cout << "Getting gammas..." << endl; int best = INT_MAX; vector<double> gammaIn; vector<LPEdge> hkSoln = getHKSolutions(fName, silent); vector<ModEdge> graph = xToZ(lpToMod(hkSoln)); vector<double> lambda = getLambda(graph); weightGraph(graph, lambda); int numNodes = getNumNodes(graph); Graph g = Graph(fName, silent); cout << "Done getting gammas" << endl; int numErrs = 0; #pragma omp parallel num_threads(4) shared(gammaIn, graph, lambda, g, numNodes) { #pragma omp for for (int i = 0; i < numSamples; i++) { int n = numNodes; int cur = getLRSTourFast(graph, lambda, g, n); #pragma omp critical { if (cur < best) best = cur; if (cur == INT_MAX) numErrs++; #pragma omp flush(best) } } } cout << "Number of errors: " << numErrs << " out of " << numSamples << " samples" << endl; return best; }