Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrazeau committed Mar 16, 2018
2 parents 21726e7 + d3ab3e7 commit cff054e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 24 deletions.
69 changes: 54 additions & 15 deletions src/fitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,57 @@ int mpl_nadown1_simpl
}


int mpl_nadown2_simpl
(MPLndsets* lset, MPLndsets* rset, MPLndsets* nset, MPLpartition* part)
{
int i = 0;
int j = 0;
int steps = 0;
const int* indices = part->charindices;
int nchars = part->ncharsinpart;
MPLstate* left = lset->downpass2;
MPLstate* right = rset->downpass2;
MPLstate* setstat = nset->uppass1;
MPLstate* npre = nset->downpass2;
MPLstate* stacts = nset->subtree_actives;
MPLstate* tstatcs = nset->temp_subtr_actives;
MPLstate* lacts = lset->subtree_actives;
MPLstate* racts = rset->subtree_actives;
MPLstate temp = 0;
unsigned long* weights = part->intwts;

for (i = 0; i < nchars; ++i) {

j = indices[i];

// TODO: Extend and test
if (setstat[j] != NA) { // If the node is not in the inapplicable state
// Do regular Fitch parsimony (sort of)
if ((temp = (left[j] & right[j]) & ISAPPLIC)) {
npre[j] = temp;
}
else {
npre[j] = (left[j] | right[j]);
if (left[j] & ISAPPLIC && right[j] & ISAPPLIC) {
if (!(npre[j] & NA)) {
steps += weights[j];
}
}
}
}
else {
npre[j] = NA;
}

#ifdef DEBUG
assert(npre[j]);
#endif
}

return 0;
}


int mpl_NA_fitch_first_update_downpass
(MPLndsets* lset, MPLndsets* rset, MPLndsets* nset, MPLpartition* part)
{
Expand Down Expand Up @@ -327,24 +378,12 @@ int mpl_naupp1_simpl

j = indices[i];

// TODO: Rewrite this
if (anc[j] == NA) {
nifin[j] = npre[j];
if (left[j] & right[j] & NA) {
nifin[j] = NA;
}
if (anc[j] == NA && npre[j] & NA) {
nifin[j] = NA;
}
else {
nifin[j] = npre[j] & anc[j];

if (nifin[j] != anc[j]) {
nifin[j] = (npre[j] | (anc[j] & (left[j] | right[j])));
}
else {
nifin[j] = nifin[j] | anc[j];
}
nifin[j] = nifin[j] & ISAPPLIC;
}

// Store the set for restoration during tree searches.
nfint[j] = nifin[j];

Expand Down
16 changes: 8 additions & 8 deletions src/morphydefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ typedef double Mflt;

typedef unsigned int MPLstate;

#define NA ((MPLstate)0b1)
#define NA ((MPLstate)1)
#define MISSING ((MPLstate)~0)
#define ISAPPLIC (((MPLstate)~0)^NA)
#define UNKNOWN ISAPPLIC
#define MAXSTATES (CHAR_BIT * sizeof(MPLstate))
#define DEFAULTGAP '-'
#define DEFAULTMISSING '?'
#define DEFAULTUNKNOWN '+'
#define DEFAULCHARTYPE FITCH_T
#define DEFAULTWTBASE 1
#define NACUTOFF 2 // The max number of NA tokens that can be ignored
Expand All @@ -45,7 +47,7 @@ typedef unsigned int MPLstate;
steer pretty clear of epsilon */

typedef struct MPLndsets MPLndsets;
typedef struct partition_s MPLpartition;
typedef struct MPLpartition MPLpartition;
// Evaluator function pointers
typedef int (*MPLdownfxn)
(MPLndsets* lset,
Expand Down Expand Up @@ -110,8 +112,7 @@ typedef struct {
} MPLcupdate;


typedef struct partition_s MPLpartition;
typedef struct partition_s {
struct MPLpartition {

MPLchtype chtype; /*!< The optimality type used for this partition. */
bool isNAtype; /*!< This character should be treated as having inapplicable data. */
Expand Down Expand Up @@ -145,11 +146,10 @@ typedef struct partition_s {
MPLloclfxn loclfxn;
MPLpartition* next;

} MPLpartition;

};


typedef struct MPLndsets {
struct MPLndsets {

bool updated;
int steps_to_recall;
Expand All @@ -169,7 +169,7 @@ typedef struct MPLndsets {
char** upp1str;
char** upp2str;

} MPLndsets;
};


typedef struct mpl_matrix_s {
Expand Down
2 changes: 1 addition & 1 deletion src/statedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ int mpl_set_gap_push(Morphyp handl)
int mpl_get_uncorrected_shift_value(char symb, Morphyp handl)
{
// Gets the raw shift value as determined by the order in the symbols list
assert(symb != DEFAULTGAP && symb != DEFAULTMISSING);
assert(symb != DEFAULTGAP && symb != DEFAULTMISSING && symb != DEFAULTUNKNOWN);
int shift = 0;
char* symbols = mpl_get_symbols((Morphy)handl);

Expand Down

0 comments on commit cff054e

Please sign in to comment.