package align2; import java.util.Arrays; public class Solver { public static final long bruteForce(int[] offsets, int[] lengths, int chunk, int minLists, int maxTotalLength){ int bits=offsets.length; int max=(1<Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)value); return; } min=value; worstIndex=i; } } // if(min>0){worstIndex=-1;} r[0]=worstIndex; r[1]=(minInteger.MAX_VALUE ? Integer.MAX_VALUE : (int)min); } public static final void findWorstGreedy(final int[] offsets, final int[] lengths, final float[] weights, final int chunk, final int[] lists, int[] r){ assert(r!=null && r.length==2); long min=Long.MAX_VALUE; int worstIndex=-1; for(int i=0; i=0; i--){ long value=valueOfElement(offsets, lengths, weights[i], chunk, lists, i); if(valueInteger.MAX_VALUE ? Integer.MAX_VALUE : (int)value); // System.out.print("."); return; } min=value; worstIndex=i; } } // if(min>0){worstIndex=-1;} r[0]=worstIndex; r[1]=(minInteger.MAX_VALUE ? Integer.MAX_VALUE : (int)min); } public static long valueOfElement(final int[] offsets, final int[] lengths, float keyWeight, final int chunk, final int[] lists, int index){ final int numlists=lists.length; if(numlists<1){return 0;} final int prospect=lists[index]; if(lengths[prospect]==0){return -999999;} long valuep=POINTS_PER_LIST+(POINTS_PER_LIST*2/lists.length)+((POINTS_PER_LIST*10)/lengths[prospect]); long valuem=POINTS_PER_SITE*lengths[prospect]; if(prospect==0 || (prospect==offsets.length-1)){ valuep+=BONUS_POINTS_FOR_END_LIST; } if(numlists==1){ valuep+=(POINTS_FOR_TOTAL_LIST_WIDTH+POINTS_PER_BASE1)*chunk; return ((long)(valuep*keyWeight))+valuem; } final int first=lists[0]; final int last=lists[numlists-1]; //Offsets of elements to the left and right of the prospect // final int offL=(prospect==first ? - : offsets[lists[index-1]]); // final int offP=offsets[prospect]; // final int offR=(prospect==last ? offsets[offsets.length-1] : offsets[lists[index+1]]); // assert(offL<=offP); // assert(offP<=offR); // assert(offL0) : "\n"+spaceScore+", "+oldLeftSpace+", "+oldRightSpace+", "+newSpace+"\n"+ Arrays.toString(offsets)+"\nprospect="+prospect+"\n"; valuep+=spaceScore; int uniquelyCovered; if(prospect==first){ uniquelyCovered=offR-offP; //Technically, -1 should be added }else if(prospect==last){ uniquelyCovered=offP-offL; //Technically, -1 should be added }else{ int a=offL+chunk; int b=offR-a; uniquelyCovered=(b>0 ? b : 0); } if(prospect==first || prospect==last){ valuep+=(POINTS_PER_BASE1+POINTS_FOR_TOTAL_LIST_WIDTH)*uniquelyCovered; }else{ valuep+=POINTS_PER_BASE1*uniquelyCovered; } return ((long)(valuep*keyWeight))+valuem; } public static int[] toBitList(final int key){ final int numlists=Integer.bitCount(key); final int[] lists=new int[numlists]; for(int i=0, ptr=0; ptr0); final int[] lists=new int[numlists]; for(int i=0, ptr=0; ptrchunk ? space-chunk : 0; score+=MULT_FOR_SPACING_PENALTY*(space*space); score-=POINTS_PER_BASE1*uncovered; } if(first>0){ long x=offsets[first]; score+=MULT_FOR_SPACING_PENALTY*(x*x); score-=POINTS_PER_BASE1*x; } if(last<(offsets.length-1)){ long x=offsets[offsets.length-1]-offsets[last]; score+=MULT_FOR_SPACING_PENALTY*(x*x); score-=POINTS_PER_BASE1*x; } return score; } public static final int BASE_POINTS_PER_SITE=-50; //Used to set POINTS_PER_SITE public static long POINTS_PER_SITE=-50; //TODO: Make private with a get() and set() function public static final long MULT_FOR_SPACING_PENALTY=-30; public static long EARLY_TERMINATION_SCORE=(POINTS_PER_SITE*2000); //TODO: Should be set dynamically public static final long POINTS_PER_LIST=30000; public static final long POINTS_PER_BASE1=6000; //Points for a base covered once public static final long POINTS_PER_BASE2=1000;//POINTS_PER_BASE1/4; //Points for a base covered twice public static final long BONUS_POINTS_FOR_END_LIST=40000; //Extra points for the first and last list public static final long POINTS_FOR_TOTAL_LIST_WIDTH=5500; //multiplier for distance between first and last list public static final long[] masks=new long[64]; public static final int[] masks32=new int[32]; static{ for(int i=0; i