| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 615 人关注过本帖
标题:[求助]源码查错
只看楼主 加入收藏
KEVIN1050
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-9-30
收藏
 问题点数:0 回复次数:6 
[求助]源码查错

JAVA才学了几天就开始学数据结构,这个程序怎么看都看不懂哪里出错了,能否帮忙指正一下?

不胜感激!

import java.until.random;
class SequenceAlignment1{
/*

using main with two command line arguments will align the
arguments with minimum cost according to the meassure +1 for
mismatches and indels, 0 for matches.

*/
private string[] character=[ A ,R, N, D, C, Q, E, G, H, I, L, K, M, F, P, S, T, W, Y,V];
private int[][] scores =
/* A R N D C Q E G H I L K M F P S T W Y V */
{ /* A */ { 5 },
/* R */ { -2, 7 },
/* N */ { -1,-1, 7 },
/* D */ { -2,-2, 2, 8 },
/* C */ { -1,-4,-2,-4,13 },
/* Q */ { -1, 1, 0, 0,-3, 7 },
/* E */ { -1, 0, 0, 2,-3, 2, 6 },
/* G */ { 0,-3, 0,-1,-3,-2,-3, 8 },
/* H */ { -2, 0, 1,-1,-3, 1, 0,-2,10 },
/* I */ { -1,-4,-3,-4,-2,-3,-4,-4,-4, 5 },
/* L */ { -2,-3,-4,-4,-2,-2,-3,-4,-3, 2, 5 },
/* K */ { -1, 3, 0,-1,-3, 2, 1,-2, 0,-3,-3, 6 },
/* M */ { -1,-2,-2,-4,-2, 0,-2,-3,-1, 2, 3,-2, 7 },
/* F */ { -3,-3,-4,-5,-2,-4,-3,-4,-1, 0, 1,-4, 0, 8 },
/* P */ { -1,-3,-2,-1,-4,-1,-1,-2,-2,-3,-4,-1,-3,-4,10 },
/* S */ { 1,-1, 1, 0,-1, 0,-1, 0,-1,-3,-3, 0,-2,-3,-1, 5 },
/* T */ { 0,-1, 0,-1,-1,-1,-1,-2,-2,-1,-1,-1,-1,-2,-1, 2, 5 },
/* W */ { -3,-3,-4,-5,-5,-1,-3,-3,-3,-3,-2,-3,-1, 1,-4,-4,-3,15 },
/* Y */ { -2,-1,-2,-3,-3,-1,-2,-3, 2,-1,-1,-2, 0, 4,-3,-2,-2, 2, 8 },
/* V */ { 0,-3,-3,-4,-1,-3,-3,-4,-4, 4, 1,-3, 1,-1,-3,-2, 0,-3,-1, 5 }
/* A R N D C Q E G H I L K M F P S T W Y V */
};
int convert(string x)
{ /* A R N D C Q E G H I L K M F P S T W Y V */

int index;
switch(x){
case A: index=0;break;
case R: index=1;break;
case N: index=2;break;
case D: index=3;break;
case C: index=4;break;
case Q: index=5;break;
case E: index=6;break;
case G: index=7;break;
case H: index=8;break;
case I: index=9;break;
case L: index=10;break;
case K: index=11;break;
case M: index=12;break;
case F: index=13;break;
case P: index=14;break;
case S: index=15;break;
case T: index=16;break;
case W: index=17;break;
case Y: index=18;break;
case V: index=19;break;
default:break;
}
return a;
}
int getscore(string a,string b){
int i,j;
i=convert(a);
j=convert(b);
if(score)
score=scores[i][j];
else
score=scores[j][i];
}
public static void main(String[] args){
/*SequenceAlignment1 sa1 = new SequenceAlignment1(string[] cmdLn);
String[] res = sa1.getAlignment();
System.out.println(sa1.getValue());
System.out.println(res[0]);
System.out.println(res[1]);*/

Random generator=new Random();
//int r=generator.nextInt();
for(int j=0;j<cmdLn.length;j++){
int randomIndex=generator.nextInt(19);
string b;
b=character[randomIndex];
}


String xs, ys; // the seqs to be aligned.
int n, m; // their lengths.
int[][] M; // the matrix used to compute the optimal values
Coord[][] traceback;

public SequenceAlignment1(String a, String b){
xs = a;
ys = b;
n = a.length();
m = b.length();
M = new int[n+1][m+1];

traceback = new Coord[n+1][m+1];

for(int i = 1; i<=n; i++){
M[i][0] = i*(-8);
traceback[i][0]=new Coord(i-1,0);
}

for(int j = 1; j<=m; j++){
M[0][j] = j*(-8);
traceback[0][j]=new Coord(0,j-1);
}

for(int i = 1; i<=n; i++)
for(int j = 1; j<=m; j++){
M[i][j] = max(M[i-1][j-1]+d(xs.charAt(i-1),ys.charAt(j-1)),
M[i-1][j]-8,
M[i][j-1]-8);
if(M[i][j] == M[i-1][j-1]+d(xs.charAt(i-1),ys.charAt(j-1)))
traceback[i][j] = new Coord(i-1,j-1);
else if (M[i][j]==M[i-1][j]-8)
traceback[i][j] = new Coord(i-1,j);
else traceback[i][j] = new Coord(i,j-1);
}
}

public int getValue(){return M[n][m];}


public String[] getAlignment(){
Coord tb = new Coord(n,m);
StringBuffer res1 = new StringBuffer();
StringBuffer res2 = new StringBuffer();
int i = tb.i;
int j = tb.j;
tb=traceback[n][m];
while(tb!=null){
if(i==tb.i)res1.append('-');
else res1.append(xs.charAt(i-1));
if(j==tb.j)res2.append('-');
else res2.append(ys.charAt(j-1));
i=tb.i;
j=tb.j;
tb = traceback[i][j];
}
String[] res = {res1.reverse().toString(),res2.reverse().toString()};
return res;
}

private static final int min(int a, int b, int c){
return Math.min(a,Math.min(b,c));
}

private static final int max(int a, int b, int c){
return Math.max(a,Math.max(b,c));
}

// The distance function:
private static final int d(char a, char b){
return a==b?0:1;
}


}

class Coord{
int i, j;
Coord(int x, int y){
i=x;j=y;
}
}



用JAVA程序,从命令行读取两个字符串,输出这两个输入的最优(佳)对比的花费(COST)和输出有着最优分数的对比(alignment)

要求用动态规划(dynamic programming)


有着最优分数(score)的一个对比(alignment)是:当对比两个各自都允许间隙(gap)的字符串时,有着最大分数(score)的对比.通过一个分数矩阵来表示字母(letter)对比的花费.假设一个间隙(gap)的花费是-8.两个字符串对比的花费是各自位置的花费的总和.


应该测量执行时间(execution time),并生成一个包含有测量及结论的文件.表示你应该写一个程序,测试序列对比中的输入(input)的大小,必须提供计算执行时间的证据


原文:
Write a java program that reads two strings from the command line and outputs the cost of an optimal alignment for the two inputs as well as one alignment with the optimal score.

The program should implement a dynamic programming algorithm.


hits:
An alignment with optimal score is one that maximizes the total score when aligning two strings alowing gaps in both strings. The cost for aligning letters is given by a score matrix 。Assume that the cost of introducing a gap is -8. The cost for the alignment of the two strings is the sum of the costs at each possition.

You should meassure the execution time of your implementation and produce the file with your meassurements and conclusions. This means that you should write a program that tests sequence alignment for some sizes of the input and that you should provide experimental evidence for the calculated asymptotic execution time

谢谢

[此贴子已经被作者于2007-10-1 18:49:04编辑过]

搜索更多相关主题的帖子: 源码 
2007-09-30 10:01
KEVIN1050
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2007-9-30
收藏
得分:0 


翻译:

用JAVA程序,从命令行读取两个字符串,输出这两个输入的最优(佳)对比的花费(COST)和输出有着最优分数的对比(alignment)

要求用动态规划(dynamic programming)

有着最优分数(score)的一个对比(alignment)是:当对比两个各自都允许间隙(gap)的字符串时,有着最大分数(score)的对比.通过一个分数矩阵来表示字母(letter)对比的花费.假设一个间隙(gap)的花费是-8.两个字符串对比的花费是各自位置的花费的总和.


应该测量执行时间(execution time),并生成一个包含有测量及结论的文件.表示你应该写一个程序,测试序列对比中的输入(input)的大小,必须提供计算执行时间的证据

2007-09-30 13:15
fearmind
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-9-28
收藏
得分:0 
不会JAVA的路过。。。

2007-09-30 13:19
imsym
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-9-28
收藏
得分:0 
楼主,对不住啊,我英语水平不高.

2007-09-30 15:34
kongxc
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:60
专家分:104
注 册:2007-9-30
收藏
得分:0 
楼主真有钻劲,值得赞扬..就是这股子劲你一定能成功的...可惜我JAVA语言不太熟悉,帮不了你...
2007-09-30 16:17
秀才
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2007-9-30
收藏
得分:0 
又一个不会java的路过。

帮你顶,等会的来。


第9帖

2007-09-30 16:18
呀汗
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2007-9-30
收藏
得分:0 
我也不知道啊。
2007-09-30 18:11
快速回复:[求助]源码查错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034946 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved