Exemplo n.º 1
0
void traceback(int i,int j)
{
	if(i==j) return;
	traceback(i,kay[i][j]);
	traceback(kay[i][j]+1,j);
	printf("\n\n M[%d][%d] * M[%d][%d] = M[%d][%d]",i,kay[i][j],kay[i][j]+1,j,i,j);
}
Exemplo n.º 2
0
int traceback(int i, int j, int y)
{
	int index;
	if(i == 0 && j == 0){
		return 0;
	}
	else if(trace[i][j] == 1){
		index = traceback(i-1, j-1, y);
		if(y == 1){/*make result[0] */
			result[0].seq[index] = pro[0].seq[i];
		}
		result[y].seq[index] = pro[y].seq[j];
	}
	else if(trace[i][j] == 2){
		index = traceback(i-1, j-1, y);
		if(y == 1){
			result[0].seq[index] = pro[0].seq[i];
		}
		result[y].seq[index] = '-';
	}
	else if(trace[i][j] == 3){
		index = traceback(i-1, j-1, y);
		if(y == 1){
			result[0].seq[index] = '-';
		}
		result[y].seq[index] = pro[y].seq[j];
	}
	return index+1;
}
Exemplo n.º 3
0
Arquivo: matrix.c Projeto: WingT/CLRS
int traceback(int i,int j)
{
	if (i==j)
		printf("M%d",i);
	else
	{
		printf("(");
		traceback(i,s[i][j]);
		traceback(s[i][j]+1,j);
		printf(")");
	}
	return 0;
}
Exemplo n.º 4
0
void traceback (int i,int j,int s[][N+1])
{
    if (i==j)
    {
        printf ("A%d",i);
    }
    else
    {
        printf ("(");
        traceback (i,s[i][j],s);
        traceback(s[i][j]+1,j,s);
        printf (")");
    }
}
Exemplo n.º 5
0
  V
  execute(const BPTableTmpl<V>& bp, std::string& paren, float gamma)
  {
    typedef V value_type;
    typedef BPTableTmpl<V> BPTable;
    typedef CYKTable< Cell<value_type> > DPTable;

    DPTable dp(bp.size()+1);
    Updater<BPTable,DPTable> update(bp, dp, gamma);
    inside_traverse(0, bp.size(), update);

    TraceBack<DPTable> traceback(paren, dp);
    traceback(0, dp.size()-1);

    return dp(0, dp.size()-1).val;
  }
Exemplo n.º 6
0
int main(int argc,char *argv[])
{
	int i, j, x, y, count, gene_num, seq_len;
	//1番目の引数で指定した転写因子の複数の結合部位配列を読み込む
	gene_num=read_promoter(argv[1]);
	for(i=0;i<gene_num;i++){
		printf(">%s\n%s\n", pro[i].name, pro[i].seq);
	}
	printf("------------------\n");
	seq_len = strlen(pro[0].seq);
	count = 0;
	for(i = 1; i < gene_num; i++){/*make genelogical tree */
		/* Compare 0 with others,
		 * it is not good way, but it is easy to implement*/
		make_map(seq_len, 0, i);
		comb[count].x = i;
		strcpy(comb[count].name, pro[i].name);
		comb[count].score = dp[seq_len-1][seq_len-1];
		count++;
	}
	make_tree(count);
	for(i = 1; i < gene_num; i++){
		make_map(seq_len, 1, i);
		if(i == 1){
			strcpy(result[0].name, pro[0].name);
		}
		strcpy(result[i].name, pro[i].name);
		traceback(seq_len-1, seq_len-1, i);
	}
	print_result(gene_num);
	return 0;
}
Exemplo n.º 7
0
/**
 * Convert a python error state to a C++ exception
 * @param withTrace If true then a traceback will be included in the exception
 * message
 * @throws std::runtime_error
 */
void throwRuntimeError(const bool withTrace) {
  GlobalInterpreterLock gil;
  if (!PyErr_Occurred()) {
    throw std::runtime_error(
        "ErrorHandling::throwRuntimeError - No Python error state set!");
  }
  PyObject *exception(nullptr), *value(nullptr), *traceback(nullptr);
  PyErr_Fetch(&exception, &value, &traceback);
  PyErr_NormalizeException(&exception, &value, &traceback);
  PyErr_Clear();
  PyObject *str_repr = PyObject_Str(value);
  std::stringstream msg;
  if (value && str_repr) {
    msg << PyString_AsString(str_repr);
  } else {
    msg << "Unknown exception has occurred.";
  }
  if (withTrace) {
    tracebackToMsg(msg, reinterpret_cast<PyTracebackObject *>(traceback));
  }

  // Ensure we decrement the reference count on the traceback and exception
  // objects as they hold references to local the stack variables that were
  // present when the exception was raised. This could include child algorithms
  // with workspaces stored that would not otherwise be cleaned up until the
  // program exited.
  Py_XDECREF(traceback);
  Py_XDECREF(exception);
  Py_XDECREF(value);
  // Raise this error as a C++ error
  throw std::runtime_error(msg.str());
}
Exemplo n.º 8
0
void bar(int x, int y)
{
  int z;
  z = x + y;
  (void) z;
  traceback(stdout);
}
Exemplo n.º 9
0
void
runtime·dopanic(int32 unused)
{
	static bool didothers;

	if(g->sig != 0)
		runtime·printf("[signal %x code=%p addr=%p pc=%p]\n",
			g->sig, g->sigcode0, g->sigcode1, g->sigpc);

	if(runtime·gotraceback()){
		if(g != m->g0) {
			runtime·printf("\n");
			runtime·goroutineheader(g);
			runtime·traceback(runtime·getcallerpc(&unused), runtime·getcallersp(&unused), 0, g);
		}
		if(!didothers) {
			didothers = true;
			runtime·tracebackothers(g);
		}
	}
	runtime·unlock(&paniclk);
	if(runtime·xadd(&runtime·panicking, -1) != 0) {
		// Some other m is panicking too.
		// Let it print what it needs to print.
		// Wait forever without chewing up cpu.
		// It will exit when it's done.
		static Lock deadlock;
		runtime·lock(&deadlock);
		runtime·lock(&deadlock);
	}

	runtime·exit(2);
}
Exemplo n.º 10
0
int  main()
{
 int n,c;
 int **m;
 cout<<"&&&&&&&&&&&&&&&&&&&&&欢迎使用0-1背包问题程序&&&&&&&&&&&&&&&&&&&"<<endl;
 cout<<"请输入物品个数和重量上限:";
 cin>>n>>c;
   int *v=new int[n+1];
 cout<<"Pls input the property (v[i]):"<<endl;
 for(int i=1;i<=n;i++)
  cin>>v[i];
 int *w=new int[n+1];
 cout<<"Pls input the weight (w[i]):"<<endl;
 for(int j=1;j<=n;j++)
  cin>>w[j];
 int *x=new int[n+1];
 m=new int*[n+1];  //动态的分配二维数组
 for(int p=0;p<n+1;p++)
 {
  m[p]=new int[c+1];
} 
 
 knapsack(v,w,c,n,m);
 traceback(m,w,c,n,x);
 
 
 cout<<endl;
 system("pause");

}
Exemplo n.º 11
0
static int lua_report(lua_State *L)
{
  traceback(L);
  report(L, -1);
  tm_runtime_exit_longjmp(255);
  return 0;
}
Exemplo n.º 12
0
// lastcontinuehandler is reached, because runtime cannot handle
// current exception. lastcontinuehandler will print crash info and exit.
uint32
runtime·lastcontinuehandler(ExceptionRecord *info, Context *r, G *gp)
{
	bool crash;

	if(runtime·panicking)	// traceback already printed
		runtime·exit(2);
	runtime·panicking = 1;

	runtime·printf("Exception %x %p %p %p\n", info->ExceptionCode,
		(uintptr)info->ExceptionInformation[0], (uintptr)info->ExceptionInformation[1], (uintptr)r->Eip);

	runtime·printf("PC=%x\n", r->Eip);
	if(g->m->lockedg != nil && g->m->ncgo > 0 && gp == g->m->g0) {
		runtime·printf("signal arrived during cgo execution\n");
		gp = g->m->lockedg;
	}
	runtime·printf("\n");

	if(runtime·gotraceback(&crash)){
		runtime·traceback(r->Eip, r->Esp, 0, gp);
		runtime·tracebackothers(gp);
		runtime·dumpregs(r);
	}
	
	if(crash)
		runtime·crash();

	runtime·exit(2);
	return 0; // not reached
}
Exemplo n.º 13
0
uint32
runtime·sighandler(ExceptionRecord *info, Context *r, G *gp)
{
	uintptr *sp;

	switch(info->ExceptionCode) {
	case EXCEPTION_BREAKPOINT:
		r->Eip--;	// because 8l generates 2 bytes for INT3
		return 1;
	}

	if(gp != nil && runtime·issigpanic(info->ExceptionCode)) {
		// Make it look like a call to the signal func.
		// Have to pass arguments out of band since
		// augmenting the stack frame would break
		// the unwinding code.
		gp->sig = info->ExceptionCode;
		gp->sigcode0 = info->ExceptionInformation[0];
		gp->sigcode1 = info->ExceptionInformation[1];
		gp->sigpc = r->Eip;

		// Only push runtime·sigpanic if r->eip != 0.
		// If r->eip == 0, probably panicked because of a
		// call to a nil func.  Not pushing that onto sp will
		// make the trace look like a call to runtime·sigpanic instead.
		// (Otherwise the trace will end at runtime·sigpanic and we
		// won't get to see who faulted.)
		if(r->Eip != 0) {
			sp = (uintptr*)r->Esp;
			*--sp = r->Eip;
			r->Esp = (uintptr)sp;
		}
		r->Eip = (uintptr)runtime·sigpanic;
		return 0;
	}

	if(runtime·panicking)	// traceback already printed
		runtime·exit(2);
	runtime·panicking = 1;

	runtime·printf("Exception %x %p %p\n", info->ExceptionCode,
		info->ExceptionInformation[0], info->ExceptionInformation[1]);

	runtime·printf("PC=%x\n", r->Eip);
	if(m->lockedg != nil && m->ncgo > 0 && gp == m->g0) {
		runtime·printf("signal arrived during cgo execution\n");
		gp = m->lockedg;
	}
	runtime·printf("\n");

	if(runtime·gotraceback()){
		runtime·traceback((void*)r->Eip, (void*)r->Esp, 0, gp);
		runtime·tracebackothers(gp);
		runtime·dumpregs(r);
	}

	runtime·exit(2);
	return 0;
}
Exemplo n.º 14
0
/* report errors and bail out if needed */
void
set_error_Loop(Loop *self, PyObject *context)
{
    if (self->debug) {
        PYEV_EXIT_LOOP(self->loop);
    }
    else {
//        PyErr_WriteUnraisable(context);
        traceback();
    }
}
Exemplo n.º 15
0
Arquivo: proc.c Projeto: machinaut/go
void
runtime·tracebackothers(G *me)
{
	G *g;

	for(g = runtime·allg; g != nil; g = g->alllink) {
		if(g == me || g->status == Gdead)
			continue;
		runtime·printf("\ngoroutine %d [%d]:\n", g->goid, g->status);
		runtime·traceback(g->sched.pc, g->sched.sp, 0, g);
	}
}
Exemplo n.º 16
0
int main(int argc,char *argv[])
{
	int i, j, k, l, f, x, y, count, gene_num, seq_len;
	//1番目の引数で指定した転写因子の複数の結合部位配列を読み込む
	gene_num=read_promoter(argv[1]);
	printf("%d", gene_num);
	for(i=0;i<gene_num;i++){
		printf(">%s\n%s\n", pro[i].name, pro[i].seq);
	}
	printf("------------------\n");
	seq_len = strlen(pro[0].seq);
	count = 0;
	for(k = 0; k < gene_num-1; k++){
		for(i = 0; i < gene_num-1; i++){/*make genelogical tree */
			for(j = i+1; j < gene_num; j++){
				f = 0;
				for(l = 0; cluster[l].name[0] != '\0'; l++){
					if(strcmp(cluster[l].name, pro[i].name) || strcmp(cluster[l].name, pro[j].name)){
						f = 1;
						break;
					}
				}
				if(f == 0){
					if(cluster[0].name[0] == '\0'){
						make_map(seq_len, i, j, 0);
					}
					else{
						make_map(seq_len, i, j, 1);
					}
					strcpy(comb[count].x_name, pro[i].name);
					strcpy(comb[count].y_name, pro[j].name);
					comb[count].x = i;
					comb[count].y = j;
					comb[count].score = dp[seq_len-1][seq_len-1];
					count++;
				}
			}
		}
		make_tree(count);
	}
	for(i = 1; i < gene_num; i++){
		make_map(seq_len, i, j, 1);
		if(i == 1){
			strcpy(result[0].name, pro[i].name);
		}
		strcpy(result[i].name, pro[i].name);
		traceback(seq_len-1, seq_len-1, i);
	}
	print_result(gene_num);
	return 0;
}
Exemplo n.º 17
0
int main ()
{
    int n;
    int q[2*N];
    int p[N+1],flag=1;
    int m[N+1][N+1];
    int s[N+1][N+1];
    printf ("请输入矩阵的个数:");
    scanf ("%d",&n);
    for (int i=0; i<=2*n-1; i++)
    {
        if (i%2==0)
        {
            printf ("***************\n");
            printf ("请输入A%d的行:",(i/2)+1);
        }
        else
        {
            printf ("列***********:");
        }
        scanf ("%d",&q[i]);
    }
    for (int i=1; i<=2*n-2; i++)
    {
        if (i%2!=0&&q[i]!=q[i+1])
        {
            flag=0;
            break;
        }
    }
    for (int j=1; j<=n-1; j++)
    {
        p[j]=q[2*j];
    }
    if (flag!=0)
    {
        p[0]=q[0];
        p[n]=q[2*n-1];
        matrixChain (p,m,s);
        printf ("式子如下:\n");
        traceback(1,n,s);
        printf ("\n");
        printf ("最小数乘次数为%d\n",m[1][n]);
    }
    else
    {
        printf ("这%d个矩阵不能连乘!\n",n);
    }
    return 0;
}
Exemplo n.º 18
0
  V
  execute(const BPTableTmpl<V>& bp, std::string& paren, uint max_dist, float gamma)
  {
    typedef V value_type;
    typedef BPTableTmpl<V> BPTable;
    typedef CYKTable< Cell<value_type> > DPTable;

    DPTable dp(bp.size()+1, max_dist);
    std::vector<Cell<value_type> > outer(bp.size()+1);
    Updater<BPTable,DPTable> update(bp, dp, gamma);
    inside_traverse(0, bp.size(), max_dist, update);
    outer[0].val = -1e100;
    outer[0].update(0.0, Rule::E);
    for (uint j=1; j!=outer.size(); ++j) {
      outer[j].val = -1e100;
      outer[j].update(outer[j-1].val, Rule::R);
      uint l = j>max_dist ? j-max_dist : 0;
      for (uint k=l; k<j; ++k) {
        if (dp(k,j).type==Rule::P)
          outer[j].update(outer[k].val+dp(k,j).val, Rule::B, k);
      }
    }

    int j=outer.size()-1;
    while (j>0) {
      if (outer[j].type==Rule::B) {
        TraceBack<DPTable> traceback(paren, dp);
        traceback(outer[j].br_pos, j);
        j = outer[j].br_pos;
      } else {
        j--;
      }
    }

    return outer.back().val;
  }
Exemplo n.º 19
0
int main(int argc,char *argv[])
{
	int i,gene_num, seq_len;
	//1番目の引数で指定した転写因子の複数の結合部位配列を読み込む
	gene_num=read_promoter(argv[1]);
	for(i=0;i<gene_num;i++){
		printf(">%s\n%s\n", pro[i].name, pro[i].seq);
	}
	printf("------------------\n");
	seq_len = strlen(pro[0].seq);
	make_map(seq_len);
	traceback(max.x, max.y, max.z);
	print_result(gene_num);
	return 0;
}
Exemplo n.º 20
0
	Alignment* SmithWaterman::align(std::string s1, std::string s2, float o, float e, float mp) {

		//fprintf(stdout, "Sequence1 = %s \n", s1.c_str());
		//fprintf(stdout, "Sequence2 = %s \n", s2.c_str());

		std::string seq1 = s1;
		std::string seq2 = s2;

		//std::cout << "add of seq1 = " << &seq1 << " add of s1 =" << &s1 << std::endl;

		int m = s1.length() + 1;
		int n = s2.length() + 1;
                if (m>600 || n>600)
                    std::cout << "m: " << m << " , n: " << n << std::endl;	
		unsigned char* pointers = new unsigned char[m*n];
		// Initializes the boundaries of the traceback matrix to STOP.
		for (int i = 0, k = 0; i < m; i++, k += n) {
			pointers[k] = STOP;
		}
		for (int j = 1; j < n; j++) {
			pointers[j] = STOP;
		}

		int* sizesOfVerticalGaps = new int[m * n];
		int* sizesOfHorizontalGaps = new int[m * n];
		for (int i = 0, k = 0; i < m; i++, k += n) {
			for (int j = 0; j < n; j++) {
				sizesOfVerticalGaps[k + j] = sizesOfHorizontalGaps[k + j] = 1;
			}
		}

		//fprintf(stdout, "Calling construct m = %d, n = %d\n", m, n);
		Cell *cell = construct(seq1, seq2, o, e, mp, pointers, sizesOfVerticalGaps, sizesOfHorizontalGaps);
		//fprintf(stdout, "Calling traceback s1 = , s2 =  \n") ;
		//Cell *cell = new Cell();
		Alignment* alignment = traceback(s1, s2,  pointers, cell, sizesOfVerticalGaps, sizesOfHorizontalGaps);
		//alignment->setName1();
		//alignment->setName2();
		//alignment.setMatrix(matrix);
		alignment->setOpen(o);
		alignment->setExtend(e);
	        //std::cout << "end of traceback call" << std::endl;
		delete cell;
		delete[] pointers;
                delete[] sizesOfVerticalGaps;
                delete[] sizesOfHorizontalGaps;
		return alignment;
	}
Exemplo n.º 21
0
/**
 * Extract the exception error string from the python interpreter.
 *
 * This function assumes the gil is acquired. See \ref python_thread_guard.
 *
 * Code adapted from http://stackoverflow.com/questions/1418015/how-to-get-python-exception-text
 */
std::string parse_python_error() {
  PyObject *exc,*val,*tb;
  PyErr_Fetch(&exc,&val,&tb);
  PyErr_NormalizeException(&exc,&val,&tb);
  python::handle<> hexc(exc),hval(python::allow_null(val)),htb(python::allow_null(tb));
  if(!hval) {
    return python::extract<std::string>(python::str(hexc));
  }
  else {
    python::object traceback(python::import("traceback"));
    python::object format_exception(traceback.attr("format_exception"));
    python::object formatted_list(format_exception(hexc,hval,htb));
    python::object formatted(python::str("").join(formatted_list));
    return python::extract<std::string>(formatted);
  }
}
Exemplo n.º 22
0
/*traceback to make result seq */
int traceback(int i, int j, int k)
{
	int index;
	if(trace[i][j][k] == 0){
		return 0;
	}
	else if(trace[i][j][k] == 1){
		index = traceback(i-1, j-1, k-1);
		pro[0].result[index] = pro[0].seq[i];
		pro[1].result[index] = pro[1].seq[j];
		pro[2].result[index] = pro[2].seq[k];
	}
	else if(trace[i][j][k] == 2){
		index = traceback(i-1, j-1, k);
		pro[0].result[index] = pro[0].seq[i];
		pro[1].result[index] = pro[1].seq[j];
		pro[2].result[index] = '-';
	}
	else if(trace[i][j][k] == 3){
		index = traceback(i-1, j, k-1);
		pro[0].result[index] = pro[0].seq[i];
		pro[1].result[index] = '-';
		pro[2].result[index] = pro[2].seq[k];
	}
	else if(trace[i][j][k] == 4){
		index = traceback(i, j-1, k-1);
		pro[0].result[index] = '-';
		pro[1].result[index] = pro[1].seq[j];
		pro[2].result[index] = pro[2].seq[k];
	}
	else if(trace[i][j][k] == 5){
		index = traceback(i-1, j, k);
		pro[0].result[index] = pro[0].seq[i];
		pro[1].result[index] = '-';
		pro[2].result[index] = '-';
	}
	else if(trace[i][j][k] == 6){
		index = traceback(i, j-1, k);
		pro[0].result[index] = '-';
		pro[1].result[index] = pro[1].seq[j];
		pro[2].result[index] = '-';
	}
	else if(trace[i][j][k] == 7){
		index = traceback(i, j, k-1);
		pro[0].result[index] = '-';
		pro[1].result[index] = '-';
		pro[2].result[index] = pro[2].seq[k];
	}
	return index+1;
}
Exemplo n.º 23
0
int main(int argc, char* argv[])
{
  
  // check argument count
  if (argc < 5)
  {
    printf("usage: %s seq1 seq2 scorematrix indelcosts\n!", argv[0]);
    return 1;
  }
  
  // read sequences and m (cost function) from command line
  char* s1 = argv[1];
  int len1 = strlen(s1);
  char* s2 = argv[2];
  int len2 = strlen(s2);
  char* filename = argv[3];
  int indel;
  sscanf(argv[4], "%d", &indel);

  printf("Sequenz 1: %s\n", s1);
  printf("Sequenz 2: %s\n", s2);

  scorematrix* sm = read_scorematrix(filename,indel);
  if (sm == NULL)
    return 1;

  // reserve memory for dynamic programing table
  alignentry*** table = initializeDP (len1+1, len2+1);

  // calculate costs for optimal alignment of s1 and s2
  int imax,jmax;
  int score = align (table, s1, len1, s2, len2, sm, &imax, &jmax);
  // print dynamic programing table
  show_DPtable(s1,len1,s2,len2,table);
  printf("Alignment: %d\n", score);

  alignment* align = alignment_new(s1,len1,s2,len2);
  traceback(table,align,imax,jmax);
  if (alignment_show(align))
  {
    puts("FEHLER: inkonsistentes Alignment!");
  }
  alignment_delete(align);
  deleteDP (table, len1+1, len2+1);

  return 0;
}
Exemplo n.º 24
0
void
runtime·tracebackothers(G *me)
{
    G *gp;
    int32 traceback;

    traceback = runtime·gotraceback();
    for(gp = runtime·allg; gp != nil; gp = gp->alllink) {
        if(gp == me || gp->status == Gdead)
            continue;
        if(gp->issystem && traceback < 2)
            continue;
        runtime·printf("\n");
        runtime·goroutineheader(gp);
        runtime·traceback(gp->sched.pc, (byte*)gp->sched.sp, 0, gp);
    }
}
MessageBrokerError::MessageBrokerError(const char *format, ...) throw() {
   va_list args;
   va_start (args, format);

   // NOTE: vsprintf doesn't check the bounds.
   vsprintf(msg_error, format, args);

   int count = strlen(msg_error);
   if(count < MessageBrokerError_LEN_BUFF_ERROR) {
      msg_error[MessageBrokerError_LEN_BUFF_ERROR-1] = 0; //guard
      count = strlen(msg_error);
      msg_error[count] = '\n';
      traceback(msg_error+count+1, MessageBrokerError_LEN_BUFF_ERROR-count-1);
   }

   msg_error[MessageBrokerError_LEN_BUFF_ERROR-1] = 0; //guard
   va_end(args);
}
Exemplo n.º 26
0
/// Adapted from http://stackoverflow.com/a/6576177/1689220
std::string pyerr_to_string(void)
{
    PyObject *exc, *val, *tb;
    bp::object formatted_list, formatted;
    PyErr_Fetch(&exc, &val, &tb);
    // wrap exception, value, traceback with bp::handle for auto memory management
    bp::handle<> hexc(exc), hval(bp::allow_null(val)), htb(bp::allow_null(tb));
    // import "traceback" module
    bp::object traceback(bp::import("traceback"));
    if (!tb) {
        bp::object format_exception_only(traceback.attr("format_exception_only"));
        formatted_list = format_exception_only(hexc, hval);
    } else {
        bp::object format_exception(traceback.attr("format_exception"));
        formatted_list = format_exception(hexc, hval, htb);
    }
    formatted = bp::str("\n").join(formatted_list);
    return bp::extract<std::string>(formatted);
}
Exemplo n.º 27
0
void main()
{
	int i,q,n;
	clrscr();
	printf("\n Number Of Matrix :");
	scanf("%d",&q);

	for(i=1;i<=q+1;i++)
	{
		printf("r[%d] :",i);
		scanf("%d",&r[i]);
	}
	chain(q);
	printf("\n\n Total Computation : %5d",c[1][5]);
	printf("\n\n Kay Value : %5d",kay[1][q]);

	traceback(1,q);
getch();
}
Exemplo n.º 28
0
Arquivo: matrix.c Projeto: WingT/CLRS
int  main(void)
{
    int n,i,*p,**m;
    scanf("%d",&n);
    p=(int *)malloc(sizeof(int)*(n+1));
    for (i=0;i<n+1;i++)
    	scanf("%d",p+i);
    m=(int **)malloc(sizeof(int *)*(n+1));
    s=(int **)malloc(sizeof(int *)*(n+1));
    for (i=0;i<n+1;i++)
    {
    	m[i]=(int *)malloc(sizeof(int)*(n+1));
    	s[i]=(int *)malloc(sizeof(int)*(n+1));
    }
    matrixchain(p,n,m,s);
    printf("%d\n",m[1][n]);
    traceback(1,n);
	return 0;
}
Exemplo n.º 29
0
alignment* optimal_alignment(char* s1, char* s2, int (*costFunc) (char, char), int* cost)
{
  int len1 = strlen(s1);
  int len2 = strlen(s2);

  // reserve memory for dynamic programing table
  alignentry*** table = initializeDP (len1+1, len2+1);
  // calculate costs for optimal alignment of s1 and s2
  *cost = align (table, s1, len1, s2, len2, costFunc);
  alignment* a = alignment_new(s1,len1,s2,len2);
  traceback(table,a,len1,len2);

  // if test-mode => show table
  #ifdef UNIT_TEST
  show_dp(table, s1, s2);
  #endif

  deleteDP (table, len1+1, len2+1);

  return a;
}
Exemplo n.º 30
0
void do_alignment(char * line1, char * line2) {

    // get start time
    double align_t = gettime();

    // prep seqs
    int seq1len = strlen(line1);
    int seq2len = strlen(line2);
    char seq1[seq1len];
    strcpy(seq1, line1);
    char seq2[seq2len];
    strcpy(seq2, line2);

    // initialize score and pointer matrices
    int * score_matrix = (int *) malloc((10000+1) * (10000+1) * sizeof(int));
    int * ptr_matrix   = (int *) malloc((10000+1) * (10000+1) * sizeof(int));

    fill_matrix(score_matrix, seq1len, seq2len, 0);
    fill_matrix(  ptr_matrix, seq1len, seq2len, 0); 
    //print_matrix(ptr_matrix, seq1len, seq2len);
    //print_matrix(score_matrix, seq1len, seq2len);

    // do the score calculation for each cell in the matrix
    int max_i = 0, max_j = 0, max_score = 0;
    walk_matrix(score_matrix, ptr_matrix, seq1, seq2, &max_i, &max_j, &max_score);

    // find the alignment by following the pointers back through the matrix
    traceback(score_matrix, ptr_matrix, seq1, seq2, max_i, max_j);

    // release matrix memory
    free(score_matrix);
    free(ptr_matrix);

    // print score
    printf("max score: %d\n", max_score);

    // print num of cells, time in secs, and flops
    align_t = gettime() - align_t;
    printf("%d\t%f\t%E\n", seq1len*seq2len, align_t, pow(seq1len*seq2len, 3)/align_t);
}