int main(int argc,char* argv[]) { if (argc < 5) { printf("%s ratio target id_start id_end\n",argv[0]); return 1; } float ratio = atof(argv[1]); int id_start = atoi(argv[3]); int id_end = atoi(argv[4]); Desc targetDesc = parseKeyFile(argv[2]); printf("Loaded %d (dim %d) keypoints from %s\n",targetDesc.n,targetDesc.dimension,argv[2]); int newDimension = 64; float* pca_basis = new float[newDimension * targetDesc.dimension]; pca(targetDesc,newDimension,pca_basis); changeBasis(&targetDesc,newDimension,pca_basis); char buffer[128]; struct timespec tic,toc; clock_gettime(CLOCK_MONOTONIC,&tic); for (int i=id_start;i<=id_end;i++) { sprintf(buffer,"%d.key",i); Desc sourceDesc = parseKeyFile(buffer); changeBasis(&sourceDesc,newDimension,pca_basis); std::vector<Match> match = findMatch(sourceDesc,targetDesc,ratio); sprintf(buffer,"%d.site.match",i); FILE* output = fopen(buffer,"w"); for (size_t i=0;i<match.size();i++) { fprintf(output,"0 %f %f 1 %f %f\n", sourceDesc.x[match[i].id1],sourceDesc.y[match[i].id1], targetDesc.x[match[i].id2],targetDesc.y[match[i].id2]); } printf("Wrote %lu matches to %s\n",match.size(),buffer); fclose(output); delete[] sourceDesc.x; delete[] sourceDesc.y; delete[] sourceDesc.data; } clock_gettime(CLOCK_MONOTONIC,&toc); printf("Profiling: %fs for %d images\n",toc.tv_sec - tic.tv_sec + 0.000000001 * toc.tv_nsec - 0.000000001 * tic.tv_nsec,id_end-id_start+1); delete[] targetDesc.x; delete[] targetDesc.y; delete[] targetDesc.data; delete[] pca_basis; }
bool Solver::iterateInt() { if(m_status != OptimalSolutionFound) return false; size_t cuti = m_height; for(size_t i=0; i < m_height; i++) { if(LimitCutoff == m_limitType[i] && m_columnB[i] < 0) { cuti = i; break; } } // basis changing if(cuti != m_height) { size_t minj = m_width; /* double minTheta = std::numeric_limits<double>::infinity(); */ for(size_t j=0; j < m_width; j++) { if(m_matrixA[cuti][j] < 0) { minj = j; break; /* FIXME: very slow double theta = m_columnB[cuti] / m_matrixA[cuti][j]; if(theta < minTheta) { minj = j; minTheta = theta; } */ // TODO: equals check } } // qDebug() << "minj" << minj << "; cuti " << cuti; if(minj == m_width) { m_status = SolutionNotExists; return true; } m_maxj = minj; m_mini = cuti; changeBasis(); m_F = 0.0; for(size_t i=0; i < m_height; i++) { m_F += m_columnB[i] * m_rowC[m_columnBasis[i]]; } return true; } for(size_t i=0; i < m_height; i++) { if(!m_variableInt[m_columnBasis[i]]) continue; if(!isInteger(m_columnB[i])) { // make goomory cutoff m_rowC.push_back(0.0); m_rowD.push_back(0.0); m_rowWD.push_back(0.0); m_variableInt.push_back(false); m_variableType.push_back(VariableCutoff); for(size_t ii=0; ii < m_height; ii++) m_matrixA[ii].push_back(0.0); // add limit std::vector<double> tmp(m_width, 0); for(size_t j=0; j < m_width; j++) tmp[j] = -fractionalPart(m_matrixA[i][j]); tmp.push_back(1.0); m_matrixA.push_back(tmp); m_columnCompareOp.push_back(Equal); m_columnTheta.push_back(0.0); m_columnB.push_back(-fractionalPart(m_columnB[i])); m_columnBasis.push_back(m_width); m_limitType.push_back(LimitCutoff); m_width++; m_height++; return true; } } m_status = OptimalIntSolutionFound; return true; }
static void init_stack_match(void) { int i; char buf[256]; char *strutName; struct patternParameter *param; double r0; double ks; double x_o; double x_g; double y_m; double vDax; double vDay; double vDbx; double vDby; if (stack_match_initialized) { return; } param = getPatternParameter("PAM5:basis-x_o"); BAIL(); x_o = param->value; param = getPatternParameter("PAM5:basis-x_g"); BAIL(); x_g = param->value; param = getPatternParameter("PAM5:basis-y_m"); BAIL(); y_m = param->value; vAh5_type = getAtomTypeByName("vAh5"); changeBasis(x_o, x_g, y_m, 0.0, 0.0, &axis_pq, &axis_pq); for (i=0; i<8 && i<numStruts; i++) { sprintf(buf, "strut-%d", i+1); param = getPatternParameter(buf); BAIL(); strutName = param->stringValue; sprintf(buf, "vDa%s", strutName); vDa_type[i] = getAtomTypeByName(buf); sprintf(buf, "vDb%s", strutName); vDb_type[i] = getAtomTypeByName(buf); sprintf(buf, "PAM5-Stack:vDa%s-x", strutName); param = getPatternParameter(buf); BAIL(); vDax = param->value; sprintf(buf, "PAM5-Stack:vDa%s-y", strutName); param = getPatternParameter(buf); BAIL(); vDay = param->value; changeBasis(x_o, x_g, y_m, vDax, vDay, &vDax_p[i], &vDax_q[i]); sprintf(buf, "PAM5-Stack:vDb%s-x", strutName); param = getPatternParameter(buf); BAIL(); vDbx = param->value; sprintf(buf, "PAM5-Stack:vDb%s-y", strutName); param = getPatternParameter(buf); BAIL(); vDby = -param->value; changeBasis(x_o, x_g, y_m, vDbx, vDby, &vDbx_p[i], &vDbx_q[i]); } param = getPatternParameter("PAM5:5-Pl-Ss-3_r0"); BAIL(); r0 = param->value; // pm param = getPatternParameter("PAM5:5-Pl-Ss-3_ks"); BAIL(); ks = param->value; // N/m stretch_5_Pl_Ss_3 = newBondStretch("5-Pl-Ss-3", ks, r0, 1.0, -1.0, -1.0, 9, 1); param = getPatternParameter("PAM5:5-Ss-Pl-3_r0"); BAIL(); r0 = param->value; // pm param = getPatternParameter("PAM5:5-Ss-Pl-3_ks"); BAIL(); ks = param->value; // N/m stretch_5_Ss_Pl_3 = newBondStretch("5-Ss-Pl-3", ks, r0, 1.0, -1.0, -1.0, 9, 1); bend_Gv_Ss_Pl_5 = newBendData("Gv-Ss-Pl-5", 0.0, 0.0, 9); stack_match_initialized = 1; }