001/* 002 * $Id: ExpVectorShort.java 5377 2015-12-31 17:43:16Z kredel $ 003 */ 004 005package edu.jas.poly; 006 007 008import java.util.ArrayList; 009import java.util.List; 010 011 012/** 013 * ExpVectorShort implements exponent vectors for polynomials using arrays of 014 * short as storage unit. This class is used by ExpVector internally, there is 015 * no need to use this class directly. 016 * @see ExpVector 017 * @author Heinz Kredel 018 */ 019 020public final class ExpVectorShort extends ExpVector 021/*implements AbelianGroupElem<ExpVectorShort>*/{ 022 023 024 /** 025 * The data structure is an array of longs. 026 */ 027 /*package*/final short[] val; 028 029 030 /** 031 * Largest short. 032 */ 033 public static final long maxShort = (long) Short.MAX_VALUE / 2; 034 035 036 /** 037 * Smallest short. 038 */ 039 public static final long minShort = (long) Short.MIN_VALUE / 2; 040 041 042 /** 043 * Constructor for ExpVector. 044 * @param n length of exponent vector. 045 */ 046 public ExpVectorShort(int n) { 047 this(new short[n]); 048 } 049 050 051 /** 052 * Constructor for ExpVector. Sets exponent i to e. 053 * @param n length of exponent vector. 054 * @param i index of exponent to be set. 055 * @param e exponent to be set. 056 */ 057 public ExpVectorShort(int n, int i, short e) { 058 this(n); 059 val[i] = e; 060 } 061 062 063 /** 064 * Constructor for ExpVector. Sets exponent i to e. 065 * @param n length of exponent vector. 066 * @param i index of exponent to be set. 067 * @param e exponent to be set. 068 */ 069 public ExpVectorShort(int n, int i, long e) { 070 this(n); 071 if (e >= maxShort || e <= minShort) { 072 throw new IllegalArgumentException("exponent to large: " + e); 073 } 074 val[i] = (short) e; 075 } 076 077 078 /** 079 * Internal constructor for ExpVector. Sets val. 080 * @param v internal representation array. 081 */ 082 protected ExpVectorShort(short[] v) { 083 super(); 084 val = v; 085 } 086 087 088 /** 089 * Constructor for ExpVector. Sets val, converts from long array. 090 * @param v long representation array. 091 */ 092 public ExpVectorShort(long[] v) { 093 this(v.length); 094 for (int i = 0; i < v.length; i++) { 095 if (v[i] >= maxShort || v[i] <= minShort) { 096 throw new IllegalArgumentException("exponent to large: " + v[i]); 097 } 098 val[i] = (short) v[i]; 099 } 100 } 101 102 103 /** 104 * Constructor for ExpVector. Converts a String representation to an 105 * ExpVector. Accepted format = (1,2,3,4,5,6,7). 106 * @param s String representation. 107 */ 108 public ExpVectorShort(String s) throws NumberFormatException { 109 super(); 110 // first format = (1,2,3,4,5,6,7) 111 List<Short> exps = new ArrayList<Short>(); 112 s = s.trim(); 113 int b = s.indexOf('('); 114 int e = s.indexOf(')', b + 1); 115 String teil; 116 int k; 117 short a; 118 if (b >= 0 && e >= 0) { 119 b++; 120 while ((k = s.indexOf(',', b)) >= 0) { 121 teil = s.substring(b, k); 122 a = Short.parseShort(teil); 123 exps.add(Short.valueOf(a)); 124 b = k + 1; 125 } 126 if (b <= e) { 127 teil = s.substring(b, e); 128 a = Short.parseShort(teil); 129 exps.add(Short.valueOf(a)); 130 } 131 int length = exps.size(); 132 val = new short[length]; 133 for (int j = 0; j < length; j++) { 134 val[j] = exps.get(j).shortValue(); 135 } 136 } else { 137 // not implemented 138 val = null; 139 // length = -1; 140 //Vector names = new Vector(); 141 //vars = s; 142 } 143 } 144 145 146 /** 147 * Clone this. 148 * @see java.lang.Object#clone() 149 */ 150 @Override 151 public ExpVectorShort copy() { 152 short[] w = new short[val.length]; 153 System.arraycopy(val, 0, w, 0, val.length); 154 return new ExpVectorShort(w); 155 } 156 157 158 /** 159 * Get the exponent vector. 160 * @return val as long. 161 */ 162 @Override 163 public long[] getVal() { 164 long v[] = new long[val.length]; 165 for (int i = 0; i < val.length; i++) { 166 v[i] = val[i]; 167 } 168 return v; 169 } 170 171 172 /** 173 * Get the exponent at position i. 174 * @param i position. 175 * @return val[i]. 176 */ 177 @Override 178 public long getVal(int i) { 179 return val[i]; 180 } 181 182 183 /** 184 * Set the exponent at position i to e. 185 * @param i 186 * @param e 187 * @return old val[i]. 188 */ 189 @Override 190 protected long setVal(int i, long e) { 191 short x = val[i]; 192 if (e >= maxShort || e <= minShort) { 193 throw new IllegalArgumentException("exponent to large: " + e); 194 } 195 val[i] = (short) e; 196 hash = 0; // beware of race condition 197 return x; 198 } 199 200 201 /** 202 * Set the exponent at position i to e. 203 * @param i 204 * @param e 205 * @return old val[i]. 206 */ 207 protected short setVal(int i, short e) { 208 short x = val[i]; 209 val[i] = e; 210 hash = 0; // beware of race condition 211 return x; 212 } 213 214 215 /** 216 * Get the length of this exponent vector. 217 * @return val.length. 218 */ 219 @Override 220 public int length() { 221 return val.length; 222 } 223 224 225 /** 226 * Extend variables. Used e.g. in module embedding. Extend this by i 227 * elements and set val[j] to e. 228 * @param i number of elements to extend. 229 * @param j index of element to be set. 230 * @param e new exponent for val[j]. 231 * @return extended exponent vector. 232 */ 233 @Override 234 public ExpVectorShort extend(int i, int j, long e) { 235 short[] w = new short[val.length + i]; 236 System.arraycopy(val, 0, w, i, val.length); 237 if (j >= i) { 238 throw new IllegalArgumentException("i " + i + " <= j " + j + " invalid"); 239 } 240 if (e >= maxShort || e <= minShort) { 241 throw new IllegalArgumentException("exponent to large: " + e); 242 } 243 w[j] = (short) e; 244 return new ExpVectorShort(w); 245 } 246 247 248 /** 249 * Extend lower variables. Extend this by i lower elements and set val[j] to 250 * e. 251 * @param i number of elements to extend. 252 * @param j index of element to be set. 253 * @param e new exponent for val[j]. 254 * @return extended exponent vector. 255 */ 256 @Override 257 public ExpVectorShort extendLower(int i, int j, long e) { 258 short[] w = new short[val.length + i]; 259 System.arraycopy(val, 0, w, 0, val.length); 260 if (j >= i) { 261 throw new IllegalArgumentException("i " + i + " <= j " + j + " invalid"); 262 } 263 w[val.length + j] = (short) e; 264 return new ExpVectorShort(w); 265 } 266 267 268 /** 269 * Contract variables. Used e.g. in module embedding. Contract this to len 270 * elements. 271 * @param i position of first element to be copied. 272 * @param len new length. 273 * @return contracted exponent vector. 274 */ 275 @Override 276 public ExpVectorShort contract(int i, int len) { 277 if (i + len > val.length) { 278 throw new IllegalArgumentException("len " + len + " > val.len " + val.length); 279 } 280 short[] w = new short[len]; 281 System.arraycopy(val, i, w, 0, len); 282 return new ExpVectorShort(w); 283 } 284 285 286 /** 287 * Reverse variables. Used e.g. in opposite rings. 288 * @return reversed exponent vector. 289 */ 290 @Override 291 public ExpVectorShort reverse() { 292 short[] w = new short[val.length]; 293 for (int i = 0; i < val.length; i++) { 294 w[i] = val[val.length - 1 - i]; 295 } 296 return new ExpVectorShort(w); 297 } 298 299 300 /** 301 * Reverse lower j variables. Used e.g. in opposite rings. Reverses the 302 * first j-1 variables, the rest is unchanged. 303 * @param j index of first variable reversed. 304 * @return reversed exponent vector. 305 */ 306 @Override 307 public ExpVectorShort reverse(int j) { 308 if (j <= 0 || j > val.length) { 309 return this; 310 } 311 short[] w = new short[val.length]; 312 for (int i = 0; i < j; i++) { 313 w[i] = val[i]; 314 } 315 // copy rest 316 for (int i = j; i < val.length; i++) { 317 w[i] = val[val.length + j - 1 - i]; 318 } 319 return new ExpVectorShort(w); 320 } 321 322 323 /** 324 * Combine with ExpVector. Combine this with the other ExpVector V. 325 * @param V the other exponent vector. 326 * @return combined exponent vector. 327 */ 328 @Override 329 public ExpVectorShort combine(ExpVector V) { 330 if (V == null || V.length() == 0) { 331 return this; 332 } 333 ExpVectorShort Vi = (ExpVectorShort) V; 334 if (val.length == 0) { 335 return Vi; 336 } 337 short[] w = new short[val.length + Vi.val.length]; 338 System.arraycopy(val, 0, w, 0, val.length); 339 System.arraycopy(Vi.val, 0, w, val.length, Vi.val.length); 340 return new ExpVectorShort(w); 341 } 342 343 344 /** 345 * Permutation of exponent vector. 346 * @param P permutation. 347 * @return P(e). 348 */ 349 @Override 350 public ExpVectorShort permutation(List<Integer> P) { 351 short[] w = new short[val.length]; 352 int j = 0; 353 for (Integer i : P) { 354 w[j++] = val[i]; 355 } 356 return new ExpVectorShort(w); 357 } 358 359 360 /** 361 * Get the string representation. 362 * @see java.lang.Object#toString() 363 */ 364 @Override 365 public String toString() { 366 return super.toString() + ":short"; 367 } 368 369 370 /** 371 * Comparison with any other object. 372 * @see java.lang.Object#equals(java.lang.Object) 373 */ 374 @Override 375 public boolean equals(Object B) { 376 if (!(B instanceof ExpVectorShort)) { 377 return false; 378 } 379 ExpVectorShort b = (ExpVectorShort) B; 380 int t = this.invLexCompareTo(b); 381 //System.out.println("equals: this = " + this + " B = " + B + " t = " + t); 382 return (0 == t); 383 } 384 385 386 /** 387 * hashCode for this exponent vector. 388 * @see java.lang.Object#hashCode() Only for findbugs. 389 */ 390 @Override 391 public int hashCode() { 392 return super.hashCode(); 393 } 394 395 396 /** 397 * ExpVector absolute value. 398 * @return abs(this). 399 */ 400 @Override 401 public ExpVectorShort abs() { 402 short[] u = val; 403 short[] w = new short[u.length]; 404 for (int i = 0; i < u.length; i++) { 405 if (u[i] >= 0L) { 406 w[i] = u[i]; 407 } else { 408 w[i] = (short) (-u[i]); 409 } 410 } 411 return new ExpVectorShort(w); 412 //return EVABS(this); 413 } 414 415 416 /** 417 * ExpVector negate. 418 * @return -this. 419 */ 420 @Override 421 public ExpVectorShort negate() { 422 short[] u = val; 423 short[] w = new short[u.length]; 424 for (int i = 0; i < u.length; i++) { 425 w[i] = (short) (-u[i]); 426 } 427 return new ExpVectorShort(w); 428 // return EVNEG(this); 429 } 430 431 432 /** 433 * ExpVector summation. 434 * @param V 435 * @return this+V. 436 */ 437 @Override 438 public ExpVectorShort sum(ExpVector V) { 439 short[] u = val; 440 short[] v = ((ExpVectorShort) V).val; 441 short[] w = new short[u.length]; 442 for (int i = 0; i < u.length; i++) { 443 w[i] = (short) (u[i] + v[i]); 444 } 445 return new ExpVectorShort(w); 446 // return EVSUM(this, V); 447 } 448 449 450 /** 451 * ExpVector subtract. Result may have negative entries. 452 * @param V 453 * @return this-V. 454 */ 455 @Override 456 public ExpVectorShort subtract(ExpVector V) { 457 short[] u = val; 458 short[] v = ((ExpVectorShort) V).val; 459 short[] w = new short[u.length]; 460 for (int i = 0; i < u.length; i++) { 461 w[i] = (short) (u[i] - v[i]); 462 } 463 return new ExpVectorShort(w); 464 //return EVDIF(this, V); 465 } 466 467 468 /** 469 * ExpVector substitution. Clone and set exponent to d at position i. 470 * @param i position. 471 * @param d new exponent. 472 * @return substituted ExpVector. 473 */ 474 public ExpVectorShort subst(int i, short d) { 475 ExpVectorShort V = this.copy(); 476 //long e = 477 V.setVal(i, d); 478 return V; 479 //return EVSU(this, i, d); 480 } 481 482 483 /** 484 * ExpVector substitution. Clone and set exponent to d at position i. 485 * @param i position. 486 * @param d new exponent. 487 * @return substituted ExpVector. 488 */ 489 @Override 490 public ExpVectorShort subst(int i, long d) { 491 ExpVectorShort V = this.copy(); 492 //long e = 493 V.setVal(i, d); 494 return V; 495 //return EVSU(this, i, d); 496 } 497 498 499 /** 500 * ExpVector signum. 501 * @return 0 if this is zero, -1 if some entry is negative, 1 if no entry is 502 * negative and at least one entry is positive. 503 */ 504 @Override 505 public int signum() { 506 int t = 0; 507 short[] u = val; 508 for (int i = 0; i < u.length; i++) { 509 if (u[i] < 0) { 510 return -1; 511 } 512 if (u[i] > 0) { 513 t = 1; 514 } 515 } 516 return t; 517 //return EVSIGN(this); 518 } 519 520 521 /** 522 * ExpVector total degree. 523 * @return sum of all exponents. 524 */ 525 @Override 526 public long totalDeg() { 527 long t = 0; 528 short[] u = val; // U.val; 529 for (int i = 0; i < u.length; i++) { 530 t += u[i]; 531 } 532 return t; 533 //return EVTDEG(this); 534 } 535 536 537 /** 538 * ExpVector maximal degree. 539 * @return maximal exponent. 540 */ 541 @Override 542 public long maxDeg() { 543 long t = 0; 544 short[] u = val; 545 for (int i = 0; i < u.length; i++) { 546 if (u[i] > t) { 547 t = u[i]; 548 } 549 } 550 return t; 551 //return EVMDEG(this); 552 } 553 554 555 /** 556 * ExpVector weighted degree. 557 * @param w weights. 558 * @return weighted sum of all exponents. 559 */ 560 @Override 561 public long weightDeg(long[][] w) { 562 if (w == null || w.length == 0) { 563 return totalDeg(); // assume weight 1 564 } 565 long t = 0; 566 short[] u = val; 567 for (int j = 0; j < w.length; j++) { 568 long[] wj = w[j]; 569 for (int i = 0; i < u.length; i++) { 570 t += wj[i] * u[i]; 571 } 572 } 573 return t; 574 //return EVWDEG( w, this ); 575 } 576 577 578 /** 579 * ExpVector least common multiple. 580 * @param V 581 * @return component wise maximum of this and V. 582 */ 583 @Override 584 public ExpVectorShort lcm(ExpVector V) { 585 short[] u = val; 586 short[] v = ((ExpVectorShort) V).val; 587 short[] w = new short[u.length]; 588 for (int i = 0; i < u.length; i++) { 589 w[i] = (u[i] >= v[i] ? u[i] : v[i]); 590 } 591 return new ExpVectorShort(w); 592 //return EVLCM(this, V); 593 } 594 595 596 /** 597 * ExpVector greatest common divisor. 598 * @param V 599 * @return component wise minimum of this and V. 600 */ 601 @Override 602 public ExpVectorShort gcd(ExpVector V) { 603 short[] u = val; 604 short[] v = ((ExpVectorShort) V).val; 605 short[] w = new short[u.length]; 606 for (int i = 0; i < u.length; i++) { 607 w[i] = (u[i] <= v[i] ? u[i] : v[i]); 608 } 609 return new ExpVectorShort(w); 610 //return EVGCD(this, V); 611 } 612 613 614 /** 615 * ExpVector dependent variables. 616 * @return number of indices where val has positive exponents. 617 */ 618 public int dependentVariables() { 619 int l = 0; 620 for (int i = 0; i < val.length; i++) { 621 if (val[i] > 0) { 622 l++; 623 } 624 } 625 return l; 626 } 627 628 629 /** 630 * ExpVector dependency on variables. 631 * @return array of indices where val has positive exponents. 632 */ 633 @Override 634 public int[] dependencyOnVariables() { 635 short[] u = val; 636 int l = dependentVariables(); 637 int[] dep = new int[l]; 638 if (l == 0) { 639 return dep; 640 } 641 int j = 0; 642 for (int i = 0; i < u.length; i++) { 643 if (u[i] > 0) { 644 dep[j] = i; 645 j++; 646 } 647 } 648 return dep; 649 } 650 651 652 /** 653 * ExpVector multiple test. Test if this is component wise greater or equal 654 * to V. 655 * @param V 656 * @return true if this is a multiple of V, else false. 657 */ 658 @Override 659 public boolean multipleOf(ExpVector V) { 660 short[] u = val; 661 short[] v = ((ExpVectorShort) V).val; 662 boolean t = true; 663 for (int i = 0; i < u.length; i++) { 664 if (u[i] < v[i]) { 665 return false; 666 } 667 } 668 return t; 669 //return EVMT(this, V); 670 } 671 672 673 /** 674 * ExpVector compareTo. 675 * @param V 676 * @return 0 if U == V, -1 if U < V, 1 if U > V. 677 */ 678 @Override 679 public int compareTo(ExpVector V) { 680 return this.invLexCompareTo(V); 681 } 682 683 684 /** 685 * ExpVector inverse lexicographical compareTo. 686 * @param V 687 * @return 0 if U == V, -1 if U < V, 1 if U > V. 688 */ 689 @Override 690 public int invLexCompareTo(ExpVector V) { 691 short[] u = val; 692 short[] v = ((ExpVectorShort) V).val; 693 int t = 0; 694 for (int i = 0; i < u.length; i++) { 695 if (u[i] > v[i]) 696 return 1; 697 if (u[i] < v[i]) 698 return -1; 699 } 700 return t; 701 //return EVILCP(this, V); 702 } 703 704 705 /** 706 * ExpVector inverse lexicographical compareTo. 707 * @param V 708 * @param begin 709 * @param end 710 * @return 0 if U == V, -1 if U < V, 1 if U > V. 711 */ 712 @Override 713 public int invLexCompareTo(ExpVector V, int begin, int end) { 714 short[] u = val; 715 short[] v = ((ExpVectorShort) V).val; 716 if (begin < 0) { 717 begin = 0;; 718 } 719 if (end >= val.length) { 720 end = val.length; 721 } 722 int t = 0; 723 for (int i = begin; i < end; i++) { 724 if (u[i] > v[i]) 725 return 1; 726 if (u[i] < v[i]) 727 return -1; 728 } 729 return t; 730 //return EVILCP(this, V, begin, end); 731 } 732 733 734 /** 735 * ExpVector inverse graded lexicographical compareTo. 736 * @param V 737 * @return 0 if U == V, -1 if U < V, 1 if U > V. 738 */ 739 @Override 740 public int invGradCompareTo(ExpVector V) { 741 short[] u = val; 742 short[] v = ((ExpVectorShort) V).val; 743 int t = 0; 744 int i; 745 for (i = 0; i < u.length; i++) { 746 if (u[i] > v[i]) { 747 t = 1; 748 break; 749 } 750 if (u[i] < v[i]) { 751 t = -1; 752 break; 753 } 754 } 755 if (t == 0) { 756 return t; 757 } 758 long up = 0; 759 long vp = 0; 760 for (int j = i; j < u.length; j++) { 761 up += u[j]; 762 vp += v[j]; 763 } 764 if (up > vp) { 765 t = 1; 766 } else { 767 if (up < vp) { 768 t = -1; 769 } 770 } 771 return t; 772 //return EVIGLC(this, V); 773 } 774 775 776 /** 777 * ExpVector inverse graded lexicographical compareTo. 778 * @param V 779 * @param begin 780 * @param end 781 * @return 0 if U == V, -1 if U < V, 1 if U > V. 782 */ 783 @Override 784 public int invGradCompareTo(ExpVector V, int begin, int end) { 785 short[] u = val; 786 short[] v = ((ExpVectorShort) V).val; 787 if (begin < 0) { 788 begin = 0;; 789 } 790 if (end >= val.length) { 791 end = val.length; 792 } 793 int t = 0; 794 int i; 795 for (i = begin; i < end; i++) { 796 if (u[i] > v[i]) { 797 t = 1; 798 break; 799 } 800 if (u[i] < v[i]) { 801 t = -1; 802 break; 803 } 804 } 805 if (t == 0) { 806 return t; 807 } 808 long up = 0; 809 long vp = 0; 810 for (int j = i; j < end; j++) { 811 up += u[j]; 812 vp += v[j]; 813 } 814 if (up > vp) { 815 t = 1; 816 } else { 817 if (up < vp) { 818 t = -1; 819 } 820 } 821 return t; 822 //return EVIGLC(this, V, begin, end); 823 } 824 825 826 /** 827 * ExpVector reverse inverse lexicographical compareTo. 828 * @param V 829 * @return 0 if U == V, -1 if U < V, 1 if U > V. 830 */ 831 @Override 832 public int revInvLexCompareTo(ExpVector V) { 833 short[] u = val; 834 short[] v = ((ExpVectorShort) V).val; 835 int t = 0; 836 for (int i = u.length - 1; i >= 0; i--) { 837 if (u[i] > v[i]) 838 return 1; 839 if (u[i] < v[i]) 840 return -1; 841 } 842 return t; 843 //return EVRILCP(this, V); 844 } 845 846 847 /** 848 * ExpVector reverse inverse lexicographical compareTo. 849 * @param V 850 * @param begin 851 * @param end 852 * @return 0 if U == V, -1 if U < V, 1 if U > V. 853 */ 854 @Override 855 public int revInvLexCompareTo(ExpVector V, int begin, int end) { 856 short[] u = val; 857 short[] v = ((ExpVectorShort) V).val; 858 if (begin < 0) { 859 begin = 0;; 860 } 861 if (end >= val.length) { 862 end = val.length; 863 } 864 int t = 0; 865 for (int i = end - 1; i >= begin; i--) { 866 if (u[i] > v[i]) 867 return 1; 868 if (u[i] < v[i]) 869 return -1; 870 } 871 return t; 872 //return EVRILCP(this, V, begin, end); 873 } 874 875 876 /** 877 * ExpVector reverse inverse graded compareTo. 878 * @param V 879 * @return 0 if U == V, -1 if U < V, 1 if U > V. 880 */ 881 @Override 882 public int revInvGradCompareTo(ExpVector V) { 883 short[] u = val; 884 short[] v = ((ExpVectorShort) V).val; 885 int t = 0; 886 int i; 887 for (i = u.length - 1; i >= 0; i--) { 888 if (u[i] > v[i]) { 889 t = 1; 890 break; 891 } 892 if (u[i] < v[i]) { 893 t = -1; 894 break; 895 } 896 } 897 if (t == 0) { 898 return t; 899 } 900 long up = 0; 901 long vp = 0; 902 for (int j = i; j >= 0; j--) { 903 up += u[j]; 904 vp += v[j]; 905 } 906 if (up > vp) { 907 t = 1; 908 } else { 909 if (up < vp) { 910 t = -1; 911 } 912 } 913 return t; 914 //return EVRIGLC(this, V); 915 } 916 917 918 /** 919 * ExpVector reverse inverse graded compareTo. 920 * @param V 921 * @param begin 922 * @param end 923 * @return 0 if U == V, -1 if U < V, 1 if U > V. 924 */ 925 @Override 926 public int revInvGradCompareTo(ExpVector V, int begin, int end) { 927 short[] u = val; 928 short[] v = ((ExpVectorShort) V).val; 929 if (begin < 0) { 930 begin = 0;; 931 } 932 if (end >= val.length) { 933 end = val.length; 934 } 935 int t = 0; 936 int i; 937 for (i = end - 1; i >= begin; i--) { 938 if (u[i] > v[i]) { 939 t = 1; 940 break; 941 } 942 if (u[i] < v[i]) { 943 t = -1; 944 break; 945 } 946 } 947 if (t == 0) { 948 return t; 949 } 950 long up = 0; 951 long vp = 0; 952 for (int j = i; j >= begin; j--) { 953 up += u[j]; 954 vp += v[j]; 955 } 956 if (up > vp) { 957 t = 1; 958 } else { 959 if (up < vp) { 960 t = -1; 961 } 962 } 963 return t; 964 //return EVRIGLC(this, V, begin, end); 965 } 966 967 968 /** 969 * ExpVector inverse weighted lexicographical compareTo. 970 * @param w weight array. 971 * @param V 972 * @return 0 if U == V, -1 if U < V, 1 if U > V. 973 */ 974 @Override 975 public int invWeightCompareTo(long[][] w, ExpVector V) { 976 short[] u = val; 977 short[] v = ((ExpVectorShort) V).val; 978 int t = 0; 979 int i; 980 for (i = 0; i < u.length; i++) { 981 if (u[i] > v[i]) { 982 t = 1; 983 break; 984 } 985 if (u[i] < v[i]) { 986 t = -1; 987 break; 988 } 989 } 990 if (t == 0) { 991 return t; 992 } 993 for (int k = 0; k < w.length; k++) { 994 long[] wk = w[k]; 995 long up = 0; 996 long vp = 0; 997 for (int j = i; j < u.length; j++) { 998 up += wk[j] * u[j]; 999 vp += wk[j] * v[j]; 1000 } 1001 if (up > vp) { 1002 return 1; 1003 } else if (up < vp) { 1004 return -1; 1005 } 1006 } 1007 return t; 1008 //return EVIWLC(w, this, V); 1009 } 1010 1011 1012 /** 1013 * ExpVector inverse weighted lexicographical compareTo. 1014 * @param w weight array. 1015 * @param V 1016 * @param begin 1017 * @param end 1018 * @return 0 if U == V, -1 if U < V, 1 if U > V. 1019 */ 1020 @Override 1021 public int invWeightCompareTo(long[][] w, ExpVector V, int begin, int end) { 1022 short[] u = val; 1023 short[] v = ((ExpVectorShort) V).val; 1024 if (begin < 0) { 1025 begin = 0;; 1026 } 1027 if (end >= val.length) { 1028 end = val.length; 1029 } 1030 int t = 0; 1031 int i; 1032 for (i = begin; i < end; i++) { 1033 if (u[i] > v[i]) { 1034 t = 1; 1035 break; 1036 } 1037 if (u[i] < v[i]) { 1038 t = -1; 1039 break; 1040 } 1041 } 1042 if (t == 0) { 1043 return t; 1044 } 1045 for (int k = 0; k < w.length; k++) { 1046 long[] wk = w[k]; 1047 long up = 0; 1048 long vp = 0; 1049 for (int j = i; j < end; j++) { 1050 up += wk[j] * u[j]; 1051 vp += wk[j] * v[j]; 1052 } 1053 if (up > vp) { 1054 return 1; 1055 } else if (up < vp) { 1056 return -1; 1057 } 1058 } 1059 return t; 1060 //return EVIWLC(w, this, V, begin, end); 1061 } 1062 1063}