Skip to content

Commit

Permalink
New fix of issue #353. Old was lost somehow.
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:vermaseren/form
  • Loading branch information
vermaseren committed Jul 17, 2020
2 parents 9e2c3d8 + 0a07b8c commit 2aabbf4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions sources/optimize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ vector<vector<WORD> > get_brackets () {
vector<vector<WORD> > brackets;

if (has_brackets) {
int exprlen=8; // we need potential space for an empty bracket
int exprlen=10; // we need potential space for an empty bracket
for (WORD *t=optimize_expr; *t!=0; t+=*t)
exprlen += *t;
WORD *newexpr = (WORD *)Malloc1(exprlen*sizeof(WORD), "optimize newexpr");
Expand Down Expand Up @@ -1642,8 +1642,8 @@ vector<WORD> simulated_annealing() {
// create a valid state where FACTORSYMBOL/SEPARATESYMBOL remains first
vector<WORD> state = occurrence_order(optimize_expr, false);
int startindex = 0;
if (state[0] == SEPARATESYMBOL || state[1] == FACTORSYMBOL) startindex++;
if (state[1] == FACTORSYMBOL) startindex++;
if ((state.size() > 0 && state[0] == SEPARATESYMBOL) || (state.size() > 1 && state[1] == FACTORSYMBOL)) startindex++;
if (state.size() > 1 && state[1] == FACTORSYMBOL) startindex++;

my_random_shuffle(BHEAD state.begin() + startindex, state.end()); // start from random scheme

Expand All @@ -1652,11 +1652,19 @@ vector<WORD> simulated_annealing() {

std::vector<WORD> best = state; // best state
int bestscore = curscore;

if (startindex == state.size() || state.size() - startindex < 2) {
return best;
}

for (int o = 0; o < AO.Optimize.saIter; o++) {
int inda = iranf(BHEAD state.size() - startindex) + startindex;
int indb = iranf(BHEAD state.size() - startindex) + startindex;

if (inda == indb) {
continue;
}

swap(state[inda], state[indb]); // swap works best for Horner

vector<WORD> tree = Horner_tree(optimize_expr, state);
Expand Down Expand Up @@ -1874,7 +1882,7 @@ inline static void next_MCTS_scheme (PHEAD vector<WORD> *porder, vector<WORD> *p
// if this a new node, create node and add children
if (!select->finished && select->childs.size()==0) {
tree_node new_node(select->var);
int sign = SGN(order.back());
int sign = (order.size() == 0) ? 1 : SGN(order.back());
for (int i=0; i<(int)mcts_vars.size(); i++)
if (!var_used.count(mcts_vars[i])) {
new_node.childs.push_back(tree_node(sign*(mcts_vars[i]+1)));
Expand Down
1 change: 1 addition & 0 deletions sources/reken.c
Original file line number Diff line number Diff line change
Expand Up @@ -3811,6 +3811,7 @@ UWORD wranf(PHEAD0)

UWORD iranf(PHEAD UWORD imax)
{
if (imax < 2) return 0;
UWORD i;
ULONG x = (LONG)1 << BITSINWORD, xmax = x - x%imax;
while ( ( i = wranf(BHEAD0) ) >= xmax ) {}
Expand Down

0 comments on commit 2aabbf4

Please sign in to comment.