-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathV_final.cpp
executable file
·68 lines (55 loc) · 1.54 KB
/
V_final.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include "V_final.h"
#include "h_struct.h"
V_final::V_final(int nb_nucleotides){
index = new int [nb_nucleotides];
int total_length = (nb_nucleotides *(nb_nucleotides+1))/2;
index[0] = 0;
int i;
for (int i=1; i < nb_nucleotides; i++)
index[i] = index[i-1]+nb_nucleotides-i+1;
type = new int[total_length];
if (type == NULL) giveup ("Cannot allocate memory", "V_final");
for (i = 0; i < total_length; i++) type[i] = -1;
// printf("an object of V_final was successfully created! \n");
}
V_final::~V_final(){
delete [] index;
delete [] type;
}
void V_final::setloops(s_energy_matrix *v, VM_final *vm){
this->v = v;
this->vm = vm;
// printf("V_final loops were successfully set! \n");
}
int V_final::get_energy(int i, int j){
// Hosna: June 28th, 2007
if (i >= j || (fres[i].pair > -1 && fres[i].pair != j) || (fres[j].pair > -1 && fres[j].pair != i)){
return INF;
}
int v_energy = v->get_energy(i,j);
/*if (i>=13 && j<=39 && v_energy<INF){
printf("V_final: v_energy(%d,%d) = %d and type = %c\n", i,j,v_energy, get_type(i,j));
}*/
int vm_energy = vm->get_energy(i,j);
// printf("V_final: vm_energy(%d,%d) = %d \n", i,j,vm_energy);
int ij = index[i]+j-i;
if (v_energy < vm_energy){
type[ij] = 0;
}else{
type[ij] = 1;
}
return MIN(v_energy,vm_energy);
}
char V_final::get_type(int i, int j){
int ij = index[i]+j-i;
if (type[ij] == 0) // comes from v
{
return v->get_type(i,j);
}
return MULTI;
}