double find_most_violated_joint_constraint_in_cache(CCACHE *ccache, SVECTOR **lhs, double *margin) /* constructs most violated joint constraint from cache. assumes that update_constraint_cache_for_model has been run. NOTE: this function returns only a shallow copy of the Psi vectors in lhs. So, do not use a deep free, otherwise the case becomes invalid. */ { double sumviol=0; int i; SVECTOR *fydelta; (*lhs)=NULL; (*margin)=0; /**** add all maximally violated fydelta to joint constraint ****/ for(i=0; i<ccache->n; i++) { fydelta=copy_svector_shallow(ccache->constlist[i]->fydelta); append_svector_list(fydelta,(*lhs)); /* add fydelta to lhs */ (*lhs)=fydelta; (*margin)+=ccache->constlist[i]->rhs; /* add loss to rhs */ sumviol+=ccache->constlist[i]->viol; } return(sumviol); }
SVECTOR *copy_svector_shallow(SVECTOR *vec) /* unlike 'copy_svector' this does not copy words and userdefined */ { SVECTOR *newvec=NULL; if(vec) { newvec=create_svector_shallow(vec->words,vec->userdefined,vec->factor); newvec->next=copy_svector_shallow(vec->next); } return(newvec); }