File: VirtualChiro.cc

package info (click to toggle)
topcom 1.2.0~beta%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 148,596 kB
  • sloc: cpp: 40,956; sh: 4,663; makefile: 679; ansic: 55
file content (99 lines) | stat: -rw-r--r-- 2,875 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
////////////////////////////////////////////////////////////////////////////////
// 
// VirtualChiro.cc
//
//    produced: 19 Nov 1999 jr
// 
////////////////////////////////////////////////////////////////////////////////

#include <assert.h>

#include "VirtualChiro.hh"

namespace topcom {

  const int VirtualChiro::operator()(const basis_type&  prebasis,
				     const Permutation& lex_extension_perm) const {
    assert(lex_extension_perm.n() == no());
    assert(lex_extension_perm.k() <= no());
    Permutation basis_perm(no(), rank() - 1, prebasis);
    basis_type basis(prebasis);
    for (size_type i = 0; i < lex_extension_perm.k(); ++i) {
      if (basis.contains(lex_extension_perm[i])) {
	continue;
      }
      basis += lex_extension_perm[i];
      const int basis_sign((*this)(basis));
      if (basis_sign == 0) {
	basis -= lex_extension_perm[i];
	continue;
      }
      basis_perm.push_back(lex_extension_perm[i]);
      int perm_sign = basis_perm.sign();
      return perm_sign * basis_sign;
    }
    return 0;
  }

  const basis_type VirtualChiro::find_non_deg_basis() const {
    if (_complete) {
      return _chiro.find_non_deg_basis();
    }
    basis_type result;
    if (_pointsptr->no() == 0) {
      return result;
    }
    if (_pointsptr->rank() == 0) {
      return result;
    }
    if (_recursive_find_non_deg_basis((*_pointsptr)[0], basis_type(0), 1, 1, result)) {
      return result;
    }
    else {
      MessageStreams::forced() << message::lock
			       << "VirtualChiro::find_non_deg_basis() const:"
			       << "no non-degenerate basis exists." << std::endl
			       << message::unlock;
      exit(1);
    }
  }

  const bool VirtualChiro::_recursive_find_non_deg_basis(const StairCaseMatrix&    current,
							 const basis_type&         basis,
							 const parameter_type      start,
							 const parameter_type      step,
							 basis_type&               result) const {
    for (parameter_type i = start; i < _pointsptr->no() - _pointsptr->rank() + step + 1; ++i) {
      StairCaseMatrix next = current;
      next.augment((*_pointsptr)[i]);
      const basis_type newbasis(basis + i);
      MessageStreams::debug() << message::lock
			      << "partial basis matrix:" << std::endl;
      next.pretty_print(MessageStreams::debug());
      MessageStreams::debug() << message::unlock;
      if (step + 1 == _pointsptr->rank()) {
	if (next.det() != 0) {
	  result = newbasis;
	  return true;
	}
      }
      else {
	if (next.has_no_zerocol()) {
#ifdef DEBUG
	  MessageStreams::debug() << message::lock
				  << "VirtualChiro::_recursive_find_non_deg_basis: "
				  << "step " << step << std::endl
				  << message::unlock;
#endif
	  if (_recursive_find_non_deg_basis(next, newbasis, i + 1, step + 1, result)) {
	    return true;
	  }
	}
      }
    }
    return false;
  }

}; // namespace topcom

// eof VirtualChiro.cc