/* IO(1) */

void get_x( int _K)
{
/* very simple test data -- for testing... */

  if( narg == 0) {

    LOADED=8;

    N = 5;	/* N data samples */
    M = 3;	/* M symbol values */
    K = 1;	/* find K best completely unmerged paths */

    states = [1:3]';

/*
    trans = reshape(1:M*M,M,M)';
*/
    trans = [ 3 2 1; 2 3 2; 1 2 3];

    zstate = 1;

    x = zeros(1,N);	/* fake input sequence */

    y = x;

    noise = 0;		/* random noise */

    z = y + noise;	/* signal plus noise */

    return;
  }

  /* narg > 0 */

  if( LOADED != 8) {
    print( "get_x: call get_x with no args first.");
    return;
  }

  M = rows(states);

  if( _K > M) {
    printf( "get_x: K > M not allowed!");
    return;
  }

  K = _K;
  combos = combinations( 1:M, K);
  perms = permutations( 1:K);
  M = rows(combos);

  zstate = 0;
}


double get_cost( double _zz, int _cur, int _next, int _j)
{
  return trans(_cur,_next);
}


vector get_ex( vector _index)
{
  vector t = states(:,1)';

  return t( _index);
}

matrix get_paths( vector _index, vector _perm, int _el)
{
  int j, c;
  matrix xex;
  vector combo;
  vector ii;

  c = cols(_index);
  xex = zeros( K, c);

  for( j = 1; j <= c; ++j) {

    if( VIT_NEW) {
      combo = combos(_index(_el,j),:);
      ii = perms( _perm(_el,j), :);
/*
      ii = perms( _vp(_index(_el,j)+j*M, _el), :); -- wrong
*/
    } else {
      combo = combos(_index(j),:);
      ii = perms( _vp(_index(j),j+1), :);
    }

    xex(:,j) = states( combo(ii), :);
  }

  return xex;
}
