All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.jas.gb.CriticalPairComparator Maven / Gradle / Ivy

The newest version!
/*
 * $Id: CriticalPairComparator.java 4052 2012-07-25 19:20:25Z kredel $
 */

package edu.jas.gb;

import java.io.Serializable;
import java.util.Comparator;

import edu.jas.structure.RingElem;

import edu.jas.poly.ExpVector;
import edu.jas.poly.TermOrder;


/**
 * Comparator for critical pairs of polynomials.
 * Immutable objects.
 * @param  coefficient type
 * @author Heinz Kredel.
 */
public class CriticalPairComparator > 
             implements Serializable, Comparator> {


    public final TermOrder tord;
    protected final TermOrder.EVComparator ec;


    /**
     * Constructor.
     * @param t TermOrder.
     */
    public CriticalPairComparator(TermOrder t){
        tord = t;
        ec = tord.getAscendComparator();
    }


    /**
     * Compare.
     * Compares exponents and if equal, compares polynomial indices.
     * @param p1 first critical pair.
     * @param p2 second critical pair.
     * @return 0 if ( p1 == p2 ), -1 if ( p1 < p2 ) and +1 if ( p1 > p2 ).
     */
    public int compare(AbstractPair p1, AbstractPair p2) {
        int s = ec.compare( p1.e, p2.e );
        if ( s == 0 ) {
            /* not ok  
           if ( p1.j < p2.j ) {
              s = -1;
           } else if ( p1.j > p2.j ) {
               s = 1;
           } else if ( p1.i < p2.i ) {
               s = -1;
           } else if ( p1.i > p2.i ) {
               s = 1;
           } else {
               s = 0;
           }
            */
           /* ok */
           if ( p1.j > p2.j ) {
              s = -1;
           } else if ( p1.j < p2.j ) {
               s = 1;
           } else if ( p1.i > p2.i ) {
               s = -1;
           } else if ( p1.i < p2.i ) {
               s = 1;
           } else {
               s = 0;
           }
           /* */
        }
        return s;
    }


    /**
     * toString.
     */
    @Override
     public String toString() {
        return "CriticalPairComparator(" + tord + ")";
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy