⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 taxonomy.cpp

📁 关联规则挖掘数据产生程序.VISUAL C++ 可产生满足要求的挖掘数据.
💻 CPP
字号:
// Taxonomy.cpp: implementation of the Taxonomy class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Taxonomy.h"

#include "Dist.h"

#include <assert.h>
#include <iomanip.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

//------------------------------ Taxonomy ------------------------------

const int Taxonomy::item_len = 7;

//
// Constructor: reads taxonomy file and builds taxonomy as a DAG
//
Taxonomy::Taxonomy(int num_items,	// total number of items
		   int num_roots,	// number of roots
		   float fanout,	// average fanout
		   float depth_ratio	// average ratio of ....
		   )
  : nitems(num_items), nroots(num_roots), depth(depth_ratio)
{
  int i, j;
  int next_child;
  PoissonDist nchildren(fanout-1);	// string length
 
  // allocate memory
  par = new int [nitems];
  child_start = new int [nitems];
  child_end = new int [nitems];

  next_child = nroots;

  // initialize parents (or lack thereof) for roots
  for (i = 0; i < nroots; i++)
    par[i] = -1;

  // set up all the interior nodes
  for (i = 0, j = next_child; i < nitems && next_child < nitems; i++)
    {
      child_start[i] = next_child;
      next_child += nchildren() + 1;
      if (next_child > nitems) 
	next_child = nitems;
      child_end[i] = next_child;
      for (; j < next_child; j++)
	par[j] = i;
    }

  // initialize children (or lack thereof) for all the leaves
  for (; i < nitems; i++)
    child_start[i] = 
    child_end[i] = -1;
}


Taxonomy::~Taxonomy(void)
{
  delete [] par;
  delete [] child_start;
  delete [] child_end;
}


void Taxonomy::write(ofstream &fp)
{
  for (int i = 0; i < nitems; i++)
    if (par[i] >= 0) {
      assert(i != par[i]);
      fp.write((char *)&i, sizeof(int));
      fp.write((char *)&par[i], sizeof(int));
    }
}


void Taxonomy::write_asc(ofstream &fp)
{
  for (int i = 0; i < nitems; i++)
    if (par[i] >= 0) {
      assert(i != par[i]);
      fp << setw(item_len) << i << " " << setw(item_len) << par[i] << endl;
    }
}


void Taxonomy::display(ofstream &fp)
{
  fp << "Taxonomy: " << endl;
  for (int i = 0; i < nitems && child_start[i] > 0; i++)
    fp << i << " " << child_start[i] << " " << child_end[i]-1 << endl;
  fp << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -