void collect_vertex_partitions(const Partition& P,      // in
			       Vtx2PartMap    & p_of_v, // out 
			       bool mark_on_boundary)   // int
{
  typedef typename Partition::PartBdVertexIterator PartBdVertexIterator;
  typedef typename Partition::grid_type   grid_type;
  typedef grid_types<grid_type>           gt;
  typedef typename gt::CellIterator             CellIterator;
  typedef typename gt::VertexOnCellIterator     VertexOnCellIterator;

  typedef BoundaryRange<grid_type>              BdRange;
  typedef typename BdRange::VertexIterator      BdVertexIterator;

  BdRange Bd(P.TheGrid());

  // add mark for vertices on grid boundary
  if(mark_on_boundary) {
    for(BdVertexIterator bv = Bd.FirstVertex(); ! bv.IsDone(); ++bv)
      p_of_v[*bv].push_back(-1);
  }
  for(CellIterator c = P.TheGrid().FirstCell(); ! c.IsDone(); ++c)
    for(VertexOnCellIterator vc = (*c).FirstVertex(); ! vc.IsDone(); ++vc) {
      int pt = P.partition(*c);
      if(std::find(p_of_v[*vc].begin(),p_of_v[*vc].end(),pt) == p_of_v[*vc].end())
	p_of_v[*vc].push_back(pt);
    }

  /*
  // add mark for vertices on boundary of partitions
  for(int pt = 0; pt < (int)P.NumOfPartitions(); ++pt) {
    for(PartBdVertexIterator pbv = P.FirstBdVertex(pt); ! pbv.IsDone(); ++pbv)
      partitions_of_vertex[*pbv].push_back(pt);
  }
  */
}
Partition ClusteringProjector::projectBackToFinest(const Partition& zetaCoarse,
		const std::vector<std::vector<node> >& maps, const Graph& Gfinest) {
	if (zetaCoarse.numberOfElements() == Gfinest.numberOfNodes()) {
		return zetaCoarse;
	}

	Partition zetaFine(Gfinest.upperNodeIdBound()); //Gfinest.numberOfNodes()
	zetaFine.setUpperBound(zetaCoarse.upperBound()); // upper bound for ids in zetaFine must be set to upper bound of zetaCoarse, or modularity assertions fail

	// store temporarily coarsest supernode here
	std::vector<node> tempMap(Gfinest.upperNodeIdBound()); //Gfinest.numberOfNodes()

	// initialize to identity
	Gfinest.parallelForNodes([&](node v){
		tempMap[v] = v;
	});

	// find coarsest supernode for each node
	for (auto iter = maps.begin(); iter != maps.end(); ++iter) {
		Gfinest.parallelForNodes([&](node v){
			tempMap[v] = (* iter)[tempMap[v]];
		});
	}


	// set clusters for fine nodes
	Gfinest.parallelForNodes([&](node v) {
		index sc = zetaCoarse[tempMap[v]];
		zetaFine.addToSubset(sc,v);//zetaFine[v] = sc;
	});

	return zetaFine;
}
Graph communicationGraph(const Graph& graph, Partition &zeta) {
	zeta.compact();
	count n = zeta.numberOfSubsets();
	Graph commGraph(n);

	if (graph.isWeighted()) {
		DEBUG("weighted");

		graph.forEdges([&](node u, node v, edgeweight w) {
			if (zeta[u] != zeta[v]) {
				commGraph.increaseWeight(zeta[u], zeta[v], w);
				TRACE("increase weight of " , zeta[u] , " and " , zeta[v] , " by " , w);
			}
		});
	} else {
		DEBUG("not weighted");

		graph.forEdges([&](node u, node v) {
			if (zeta[u] != zeta[v]) {
				commGraph.increaseWeight(zeta[u], zeta[v], 1);
				TRACE("increase weight of " , zeta[u] , " and " , zeta[v] , " by 1");
			}
		});
	}

	return commGraph;
}
示例#4
0
bool LibPartedPartitionTable::resizeFileSystem(Report& report, const Partition& partition, qint64 newLength)
{
    bool rval = false;

#if defined LIBPARTED_FS_RESIZE_LIBRARY_SUPPORT
    if (PedGeometry* originalGeometry = ped_geometry_new(pedDevice(), partition.fileSystem().firstSector(), partition.fileSystem().length())) {
        if (PedFileSystem* pedFileSystem = ped_file_system_open(originalGeometry)) {
            if (PedGeometry* resizedGeometry = ped_geometry_new(pedDevice(), partition.fileSystem().firstSector(), newLength)) {
                PedTimer* pedTimer = ped_timer_new(pedTimerHandler, nullptr);
                rval = ped_file_system_resize(pedFileSystem, resizedGeometry, pedTimer);
                ped_timer_destroy(pedTimer);

                if (!rval)
                    report.line() << xi18nc("@info:progress", "Could not resize file system on partition <filename>%1</filename>.", partition.deviceNode());
                ped_geometry_destroy(resizedGeometry);
            } else
                report.line() << xi18nc("@info:progress", "Could not get geometry for resized partition <filename>%1</filename> while trying to resize the file system.", partition.deviceNode());

            ped_file_system_close(pedFileSystem);
        } else
            report.line() << xi18nc("@info:progress", "Could not open partition <filename>%1</filename> while trying to resize the file system.", partition.deviceNode());
        ped_geometry_destroy(originalGeometry);
    } else
        report.line() << xi18nc("@info:progress", "Could not read geometry for partition <filename>%1</filename> while trying to resize the file system.", partition.deviceNode());
#else
    Q_UNUSED(report);
    Q_UNUSED(partition);
    Q_UNUSED(newLength);
#endif

    return rval;
}
示例#5
0
bool LibPartedPartitionTable::updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end)
{
    Q_ASSERT(partition.devicePath() == QString::fromUtf8(pedDevice()->path));

    bool rval = false;

    PedPartition* pedPartition = (partition.roles().has(PartitionRole::Extended))
                                 ? ped_disk_extended_partition(pedDisk())
                                 : ped_disk_get_partition_by_sector(pedDisk(), partition.firstSector());

    if (pedPartition) {
        if (PedGeometry* pedGeometry = ped_geometry_new(pedDevice(), sector_start, sector_end - sector_start + 1)) {
            if (PedConstraint* pedConstraint = ped_constraint_exact(pedGeometry)) {
                if (ped_disk_set_partition_geom(pedDisk(), pedPartition, pedConstraint, sector_start, sector_end))
                    rval = true;
                else
                    report.line() << xi18nc("@info:progress", "Could not set geometry for partition <filename>%1</filename> while trying to resize/move it.", partition.deviceNode());
                ped_constraint_destroy(pedConstraint);
            } else
                report.line() << xi18nc("@info:progress", "Could not get constraint for partition <filename>%1</filename> while trying to resize/move it.", partition.deviceNode());
            ped_geometry_destroy(pedGeometry);
        } else
            report.line() << xi18nc("@info:progress", "Could not get geometry for partition <filename>%1</filename> while trying to resize/move it.", partition.deviceNode());
    } else
        report.line() << xi18nc("@info:progress", "Could not open partition <filename>%1</filename> while trying to resize/move it.", partition.deviceNode());

    return rval;
}
示例#6
0
 bool it_should_calculate_the_original_cost ()
 {
   bool answ;
   unsigned int set_size = 12;
   ElementSet original_set ("", set_size, 100);
   bool * is_fixed = new bool[set_size];
   for (unsigned int i = 0; i < set_size; i++)
     if (i < 5)
       is_fixed[i] = true;
     else
       is_fixed[i] = false;
   Partition part (&original_set, is_fixed);
   delete[] is_fixed;
   ElementSet * fixed_set = part.get_fixed_elm_set ();
   ElementSubset part_subset ("", fixed_set);
   part_subset.add_element (0);
   part_subset.add_element (2);
   part_subset.add_element (4);
   PartitionNode P (&part, &part_subset);
   SubsetSum orig_f (&original_set);
   PartCost P_f (&orig_f, &P);
   ElementSubset X ("", part.get_unfixed_elm_set ());
   X.add_element (0);
   X.add_element (2);
   X.add_element (3);
   ElementSubset * orig_X = P.get_original_subset (&X);
   answ = orig_f.cost (orig_X) == P_f.cost (&X);
   delete orig_X;
   return answ;
 }
示例#7
0
status_t
register_boot_file_system(BootVolume& bootVolume)
{
	Directory* rootDirectory = bootVolume.RootDirectory();
	gRoot->AddLink("boot", rootDirectory);

	Partition *partition;
	status_t status = gRoot->GetPartitionFor(rootDirectory, &partition);
	if (status != B_OK) {
		dprintf("register_boot_file_system(): could not locate boot volume in "
			"root!\n");
		return status;
	}

	gBootVolume.SetInt64(BOOT_VOLUME_PARTITION_OFFSET,
		partition->offset);

	if (bootVolume.IsPackaged()) {
		gBootVolume.SetBool(BOOT_VOLUME_PACKAGED, true);
		PackageVolumeState* state = bootVolume.GetPackageVolumeState();
		if (state->Name() != NULL)
			gBootVolume.AddString(BOOT_VOLUME_PACKAGES_STATE, state->Name());
	}

	Node *device = get_node_from(partition->FD());
	if (device == NULL) {
		dprintf("register_boot_file_system(): could not get boot device!\n");
		return B_ERROR;
	}

	return platform_register_boot_device(device);
}
示例#8
0
/*!	Scans the device passed in for partitioning systems. If none are found,
	a partition containing the whole device is created.
	All created partitions are added to the gPartitions list.
*/
status_t
add_partitions_for(int fd, bool mountFileSystems, bool isBootDevice)
{
	TRACE(("add_partitions_for(fd = %d, mountFS = %s)\n", fd,
		mountFileSystems ? "yes" : "no"));

	Partition *partition = new Partition(fd);

	// set some magic/default values
	partition->block_size = 512;
	partition->size = partition->Size();

	// add this partition to the list of partitions, if it contains
	// or might contain a file system
	if ((partition->Scan(mountFileSystems, isBootDevice) == B_OK
			&& partition->IsFileSystem())
		|| (!partition->IsPartitioningSystem() && !mountFileSystems)) {
		gPartitions.Add(partition);
		return B_OK;
	}

	// if not, we no longer need the partition
	delete partition;
	return B_OK;
}
示例#9
0
bool PartitionTable::getUnallocatedRange(const Device& d, PartitionNode& parent, qint64& start, qint64& end)
{
    if (d.type() == Device::Disk_Device) {
        const DiskDevice& device = dynamic_cast<const DiskDevice&>(d);
        if (!parent.isRoot()) {
            Partition* extended = dynamic_cast<Partition*>(&parent);

            if (extended == nullptr) {
                qWarning() << "extended is null. start: " << start << ", end: " << end << ", device: " << device.deviceNode();
                return false;
            }

            // Leave a track (cylinder aligned) or sector alignment sectors (sector based) free at the
            // start for a new partition's metadata
            start += device.partitionTable()->type() == PartitionTable::msdos ? device.sectorsPerTrack() : PartitionAlignment::sectorAlignment(device);

            // .. and also at the end for the metadata for a partition to follow us, if we're not
            // at the end of the extended partition
            if (end < extended->lastSector())
                end -= device.partitionTable()->type() == PartitionTable::msdos ? device.sectorsPerTrack() : PartitionAlignment::sectorAlignment(device);
        }

        return end - start + 1 >= PartitionAlignment::sectorAlignment(device);
    } else if (d.type() == Device::LVM_Device) {
        if (end - start + 1 > 0) {
            return true;
        }
    }
    return false;
}
示例#10
0
/** @param other Partition to assign from */
Partition& Partition::operator=(const Partition& other)
{
	if (&other == this)
		return *this;

	clearChildren();

	foreach(const Partition* child, other.children())
	{
		Partition* p = new Partition(*child);
		p->setParent(this);
		m_Children.append(p);
	}

	m_Number = other.m_Number;
	m_FileSystem = FileSystemFactory::create(other.fileSystem());
	m_Roles = other.m_Roles;
	m_FirstSector = other.m_FirstSector;
	m_LastSector = other.m_LastSector;
	m_DevicePath = other.m_DevicePath;
	m_PartitionPath = other.m_PartitionPath;
	m_MountPoint = other.m_MountPoint;
	m_AvailableFlags = other.m_AvailableFlags;
	m_ActiveFlags = other.m_ActiveFlags;
	m_IsMounted = other.m_IsMounted;
	m_SectorSize = other.m_SectorSize;
	m_State = other.m_State;

	return *this;
}
示例#11
0
void
PartitionPage::onCreateClicked()
{
    QModelIndex index = m_ui->partitionTreeView->currentIndex();
    Q_ASSERT( index.isValid() );

    const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
    Partition* partition = model->partitionForIndex( index );
    Q_ASSERT( partition );

    if ( !checkCanCreate( model->device() ) )
        return;

    CreatePartitionDialog dlg(
        model->device(),
        partition->parent(),
        nullptr,
        getCurrentUsedMountpoints(),
        this );
    dlg.initFromFreeSpace( partition );
    if ( dlg.exec() == QDialog::Accepted )
    {
        Partition* newPart = dlg.createPartition();
        m_core->createPartition( model->device(), newPart, dlg.newFlags() );
    }
}
示例#12
0
TEST_F(OverlapGTest, testHashingOverlapperForCorrectness) {
	count n = 4;
	Graph G(n);

	Partition zeta(n);
	Partition eta(n);

	zeta.setUpperBound(2);
	zeta[0] = 0;
	zeta[1] = 0;
	zeta[2] = 1;
	zeta[3] = 1;

	eta.setUpperBound(2);
	eta[0] = 0;
	eta[1] = 1;
	eta[2] = 0;
	eta[3] = 1;

	std::vector<Partition> clusterings = {zeta, eta};
	HashingOverlapper overlapper;
	Partition overlap = overlapper.run(G, clusterings);

	INFO("overlap clustering number of clusters: ", overlap.numberOfSubsets());
	INFO("overlap clustering: ", overlap.getVector());
}
示例#13
0
Directory *
get_boot_file_system(stage2_args *args)
{
    Node *device;
    if (platform_add_boot_device(args, &gBootDevices) < B_OK)
        return NULL;

    // the boot device must be the first device in the list
    device = gBootDevices.First();

    if (add_partitions_for(device, false, true) < B_OK)
        return NULL;

    Partition *partition;
    if (platform_get_boot_partition(args, device, &gPartitions, &partition) < B_OK)
        return NULL;

    Directory *fileSystem;
    status_t status = partition->Mount(&fileSystem, true);

    if (status < B_OK) {
        // this partition doesn't contain any known file system; we
        // don't need it anymore
        gPartitions.Remove(partition);
        delete partition;
        return NULL;
    }

    sBootDevice = device;
    return fileSystem;
}
示例#14
0
TEST_F(OverlapGTest, testRegionGrowingOverlapperOnOneClustering) {
	int64_t n = 10;
	Graph G(n);
	G.forNodePairs([&](node u, node v){
		G.addEdge(u,v);
	});

	ClusteringGenerator clusterGen;
	std::vector<Partition> clusterings;
	int z = 3; // number of clusterings
	for (int i = 0; i < z; ++i) {
 		clusterings.push_back(clusterGen.makeOneClustering(G));
	}
	DEBUG("end of loop");

	RegionGrowingOverlapper over;
	Partition core = over.run(G, clusterings);

	// test if core clustering is one-clustering
	node v = 1;
	index one = core.subsetOf(v);
	bool isOneClustering = true; //TODO replaces with function call?
	G.forNodes([&](node v) {
		index c = core.subsetOf(v);
		DEBUG("CLUSTER! c = " , c);
		isOneClustering = isOneClustering && (c == one);
	});

	EXPECT_TRUE(isOneClustering) << "overlap of multiple 1-clustering should be a 1-clustering";

}
示例#15
0
AnalyseResult* TeConnectivity::fAnalyse(Object *iObject) {
	TeGraph *lGraph = dynamic_cast<TeGraph*>(iObject);

	TeConnResult* lConnResult = new TeConnResult();

	//----- compute -----
	INFO("Starting analysis of TE connectivity" << endl);
	Ret lRet = gAlgTimer->fStartNewTimer();

	Partition lPartition = fConn(lGraph->fGetGraph());

	if (lRet == OK) {gAlgTimer->fStopTimer();}
	INFO("Ending analysis of TE connectivity" << endl);

	//----- set results -----
	if (cOptPartition == true) {
		lConnResult->fSetPartition(lPartition);
	}
	if (cOptPartitionDet == true) {
		lConnResult->fSetPartitionDet(true);
	}
	lConnResult->fSetConn(lPartition.fGetSetCount() == 1);

	return lConnResult;
}
void Party::TransformPartitionIntoOrderedListStrategies(DifferentSizePartitions *different_size_partitions) {
    for (DifferentSizePartitions::iterator my_iterator = different_size_partitions->begin();
         my_iterator != different_size_partitions->end(); my_iterator++) {
        SameSizePartitions same_size_partitions = *my_iterator;
        SameSizeStrategies same_size_strategies;
        Strategy *strategy;
        for (SameSizePartitions::iterator same_size_iterator = same_size_partitions.begin();
             same_size_iterator != same_size_partitions.end(); same_size_iterator++) {
            Partition partition = *same_size_iterator;

            strategy = new Strategy(this);
            CandidateListInfo *to_be_find_group;
            for (Partition::iterator group_iterator = partition.begin();
                 group_iterator != partition.end(); group_iterator++) {
                GroupInPartition group_in_partition = *group_iterator;
                to_be_find_group = new CandidateListInfo();
                for (GroupInPartition::iterator my_iterator = group_in_partition.begin();
                     my_iterator != group_in_partition.end(); my_iterator++) {
                    CandidateId candidate_id = *my_iterator;
                    to_be_find_group->candidates_->push_back(candidate_id);
                }
                strategy->candidate_list_info_list_.push_back(GetExactGroupPointer(to_be_find_group));
                delete to_be_find_group;
            }

            same_size_strategies.push_back(*strategy);
            delete strategy;
        }
        strategies_with_different_size_.push_back(same_size_strategies);
    }
}
示例#17
0
TEST_F(OverlapGTest, testHashingOverlapperOnSingletonClusterings) {
	int64_t n = 10;
	Graph G(n);
	G.forNodePairs([&](node u, node v){
		G.addEdge(u,v);
	});

	ClusteringGenerator clusterGen;
	std::vector<Partition> clusterings;
	int z = 3; // number of clusterings
	for (int i = 0; i < z; ++i) {
		clusterings.push_back(clusterGen.makeSingletonClustering(G));
	}

	HashingOverlapper over;
	Partition core = over.run(G, clusterings);

	// test if core clustering is singleton-clustering
	bool isSingleton = true;
	G.forEdges([&](node u, node v) {
		isSingleton = isSingleton && (core.subsetOf(u) != core.subsetOf(v));
	});

	EXPECT_TRUE(isSingleton) << "overlap of multiple  singleton clusterings should be a singleton clustering";
}
示例#18
0
void
PartitionPage::updateButtons()
{
    bool create = false, edit = false, del = false;

    QModelIndex index = m_ui->partitionTreeView->currentIndex();
    if ( index.isValid() )
    {
        const PartitionModel* model = static_cast< const PartitionModel* >( index.model() );
        Q_ASSERT( model );
        Partition* partition = model->partitionForIndex( index );
        Q_ASSERT( partition );
        bool isFree = KPMHelpers::isPartitionFreeSpace( partition );
        bool isExtended = partition->roles().has( PartitionRole::Extended );

        create = isFree;
        // Keep it simple for now: do not support editing extended partitions as
        // it does not work with our current edit implementation which is
        // actually remove + add. This would not work with extended partitions
        // because they need to be created *before* creating logical partitions
        // inside them, so an edit must be applied without altering the job
        // order.
        edit = !isFree && !isExtended;
        del = !isFree;
    }
    m_ui->createButton->setEnabled( create );
    m_ui->editButton->setEnabled( edit );
    m_ui->deleteButton->setEnabled( del );

    m_ui->newPartitionTableButton->setEnabled( m_ui->deviceComboBox->currentIndex() >= 0 );
}
void CausalGraph::get_strongly_connected_components(Partition &result) {
    map<Variable *, int> variableToIndex;
    for(int i = 0; i < variables.size(); i++)
        variableToIndex[variables[i]] = i;

    vector<vector<int> > unweighted_graph;
    unweighted_graph.resize(variables.size());
    for(WeightedGraph::const_iterator it = weighted_graph.begin(); it
            != weighted_graph.end(); ++it) {
        int index = variableToIndex[it->first];
        vector<int> &succ = unweighted_graph[index];
        const WeightedSuccessors &weighted_succ = it->second;
        for(WeightedSuccessors::const_iterator it = weighted_succ.begin(); it
                != weighted_succ.end(); ++it)
            succ.push_back(variableToIndex[it->first]);
    }

    vector<vector<int> > int_result = SCC(unweighted_graph).get_result();

    result.clear();
    for(int i = 0; i < int_result.size(); i++) {
        vector<Variable *> component;
        for(int j = 0; j < int_result[i].size(); j++)
            component.push_back(variables[int_result[i][j]]);
        result.push_back(component);
    }
}
示例#20
0
void OTFConverter::makeSingletonPartition(CommEvent * evt)
{
    Partition * p = new Partition();
    p->addEvent(evt);
    evt->partition = p;
    p->new_partition = p;
    trace->partitions->append(p);
}
示例#21
0
  virtual double compute(const Partition& partition, const Clustering& clustering ) const {    
    double nbrChanges = nbrLabelChanges(partition);
    double expected = expectedNbrLabelChanges(clustering);
    double denominator = partition.nbrItems();

    printf("nbrItems: %d - expected: %f, nbrChanges: %f\n", partition.nbrItems(), expected, nbrChanges);
    return denominator == 0 ? 0 : 1.0 - (nbrChanges-expected)/denominator;
  }
示例#22
0
/** Copy another Partition object to this one.
 *  @param source is another Partition object
 */
void Partition::copyFrom(const Partition& source) {
	if (&source == this) return;
	if (source.n() > n()) resize(source.n());
	else clear();
	for (index x = 1; x <= source.n(); x++) {
		p(x) = source.node[x].p; rank(x) = source.node[x].rank;
	}
}
示例#23
0
bool Octree::IsPointInsidePartition(const D3DXVECTOR3& point, const Partition& partition) const
{
    const auto& minBounds = partition.GetMinBounds();
    const auto& maxBounds = partition.GetMaxBounds();
    return point.x > minBounds.x && point.x < maxBounds.x &&
           point.y < minBounds.y && point.y > maxBounds.y &&
           point.z > minBounds.z && point.z < maxBounds.z;
}
示例#24
0
bool Partition::move_to(Entity entity, Partition &dst_partition)
{
  TraceIf("stk::mesh::impl::Partition::move_to", LOG_PARTITION);
  DiagIf(LOG_PARTITION, "Moving entity: " << print_entity_key(MetaData::get(m_mesh), m_mesh.entity_key(entity)));
  TraceIfWatchingDec("stk::mesh::impl::Partition::move_to", LOG_ENTITY, m_mesh.entity_key(entity), extra);

  ThrowAssert(belongs(m_mesh.bucket(entity)));

  Bucket *src_bucket   = m_mesh.bucket_ptr(entity);
  unsigned src_ordinal = m_mesh.bucket_ordinal(entity);
  if (src_bucket && (src_bucket->getPartition() == &dst_partition))
  {
    DiagIfWatching(LOG_ENTITY, m_mesh.entity_key(entity),
                   " Already on destination partition at bucket " << *src_bucket << ", ordinal " << src_ordinal);
    return false;
  }

  ThrowRequireMsg(src_bucket && (src_bucket->getPartition() == this),
                  "Partition::move_to cannot move an entity that does not belong to it.");
  DiagIfWatching(LOG_ENTITY, m_mesh.entity_key(entity),
                 " src_bucket: " << *src_bucket << ", src_ordinal: " << src_ordinal);

  // If the last bucket is full, automatically create a new one.
  Bucket *dst_bucket = dst_partition.get_bucket_for_adds();

  ThrowErrorMsgIf(src_bucket && src_bucket->topology().is_valid() && (src_bucket->topology() != dst_bucket->topology()),
                  "Error: cannot change topology of entity (rank: "
                  << static_cast<stk::topology::rank_t>(m_mesh.entity_rank(entity))
                  << ", global_id: " << m_mesh.identifier(entity) << ") from "
                  << src_bucket->topology() << "to " << dst_bucket->topology() << "."
                  );

  dst_bucket->mesh().modified(entity);

  // Copy the entity's data to the new bucket before removing the entity from its old bucket.
  dst_bucket->copy_entity(entity);

  overwrite_from_end(*src_bucket, src_ordinal);

  dst_partition.m_updated_since_compress = dst_partition.m_updated_since_sort = true;
  dst_partition.m_size++;

  DiagIfWatching(LOG_ENTITY, m_mesh.entity_key(entity),
                 " dst_bucket: " << *dst_bucket << ", dst_ordinal: " << m_mesh.bucket_ordinal(entity));

  remove_impl();

  m_updated_since_compress = m_updated_since_sort = true;
  m_mesh.set_synchronized_count(entity, m_mesh.synchronized_count());

  DiagIf(LOG_PARTITION, "After move_to, src state is: " << *this);
  DiagIf(LOG_PARTITION, "After move_to, dst state is: " << dst_partition);

  internal_check_invariants();
  dst_partition.internal_check_invariants();

  return true;
}
示例#25
0
// 3D spatial partition
bool SpatialPartitionManager::Init(Vector3 minWorldDimension, Vector3 maxWorldDimension, Vector3 worldDivision, bool numPartitionBased, Mesh* mesh)
{
	worldDimension = maxWorldDimension - minWorldDimension;

	// ensure the data are not 0
	if (worldDimension.IsZero() || worldDivision.IsZero())
	{
		return false;
	}

	else
	{
		// divide the world base on the number of partitons given
		if (numPartitionBased)
		{
			numPartition = worldDivision;
			partitionDimension.Set(worldDimension.x / worldDivision.x, worldDimension.y / worldDivision.y, worldDimension.z / worldDivision.z);
		}

		else
		{
			partitionDimension = worldDivision;
			numPartition.Set(worldDimension.x / partitionDimension.x, worldDimension.y / partitionDimension.y, worldDimension.z / partitionDimension.z);
		}
	}

	type = PARTITION_3D;
	this->minWorldDimension = minWorldDimension;
	this->maxWorldDimension = maxWorldDimension;

	int id = 0;
	for (int k = 0; k < numPartition.z; ++k)
	{
		for (int j = 0; j < numPartition.y; ++j)
		{
			for (int i = 0; i < numPartition.x; ++i)
			{
				id = i + j * (int)numPartition.x + k * (int)numPartition.x * (int)numPartition.y;

				Partition* partition = new Partition();
				partition->Init(partitionDimension, 
					Vector3(minWorldDimension.x + i * partitionDimension.x,
							minWorldDimension.y + j * partitionDimension.y,
							minWorldDimension.z + k * partitionDimension.z),

					Vector3(minWorldDimension.x + (i + 1) * partitionDimension.x, 
							minWorldDimension.y + (j + 1) * partitionDimension.y, 
							minWorldDimension.z + (k + 1) * partitionDimension.z),
							id, 
							mesh);

				partitions.push_back(partition);
			}
		}
	}

	return true;
}
示例#26
0
Partition* FindPreferredMetadataPartition(const std::vector<Partition*>& partitions, Partition** headerPartition, Partition** footerPartition) {

	Partition *metadata_partition = NULL, *header = NULL, *footer = NULL;

	size_t i;
	for (i = partitions.size(); i > 0 ; i--) {
		Partition *p = partitions[i-1];
		if (mxf_is_header_partition_pack(p->getKey()))
			header = p;
		else if (mxf_is_footer_partition_pack(p->getKey()))
			footer = p;
	}
	 if (	header != NULL && 
			mxf_partition_is_closed(header->getKey()) &&
			header->getHeaderByteCount() > 0)
		metadata_partition = header;
	else if (	footer!=NULL && 
				mxf_partition_is_closed(footer->getKey()) && 
				footer->getHeaderByteCount() > 0)
		metadata_partition = footer;
	else {
		log_warn("No metadata found in any of the closed header and footer partitions.");

		// there is no closed header or footer partition with metadata
		// find closed metadata in any of the body partitions 
		// (header metadata might have gone lost in transit)
		for (i = partitions.size(); i > 0 ; i--) {
			Partition *p = partitions[i-1];
			if (	mxf_is_body_partition_pack(p->getKey()) &&
					mxf_partition_is_closed(p->getKey()) && 
					p->getHeaderByteCount() > 0) {
				metadata_partition = p;
				break;	// use the last partition in the file as metadata, as it should be the most complete...
			}
		}

		// is there still no metadata? Try to find metadata in open partitions
		if (metadata_partition == NULL) {
			log_warn("No metadata found in any of the closed body partitions either.");

			for (i = partitions.size(); i > 0 ; i--) {
				Partition *p = partitions[i-1];
				if (	!mxf_partition_is_closed(p->getKey()) && 
						p->getHeaderByteCount() > 0) {
					metadata_partition = p;
					break;	// use the last partition in the file as metadata, as it should be the most complete...
				}
			}
		}
	}

	if (headerPartition!=NULL)
		*headerPartition = header;
	if (footerPartition!=NULL)
		*footerPartition = footer;
	return metadata_partition;
}
float getImbalance(const Partition &zeta) {
	float avg = ceil(
			(float) zeta.numberOfElements() / (float) zeta.numberOfSubsets()); //TODO number of nodes and not number of elements
	std::vector<count> clusterSizes = zeta.subsetSizes();
	float maxClusterSize = (float) *std::max_element(clusterSizes.begin(),
			clusterSizes.end());
	float imbalance = maxClusterSize / avg;
	return imbalance;
}
示例#28
0
int
PartitionModel::rowCount( const QModelIndex& parent ) const
{
    Partition* parentPartition = partitionForIndex( parent );
    if ( parentPartition )
        return parentPartition->children().count();
    PartitionTable* table = m_device->partitionTable();
    return table ? table->children().count() : 0;
}
示例#29
0
void Octree::AddObject(CollisionMesh& object)
{
    Partition* partition = FindPartition(object, *m_octree);
    assert(partition);    

    // connect object and new partition together
    partition->AddNode(object);
    object.SetPartition(partition);
}
示例#30
0
status_t
load_modules(stage2_args* args, BootVolume& volume)
{
	int32 failed = 0;

	// ToDo: this should be mostly replaced by a hardware oriented detection mechanism

	int32 i = 0;
	for (; sAddonPaths[i]; i++) {
		char path[B_FILE_NAME_LENGTH];
		snprintf(path, sizeof(path), "%s/boot", sAddonPaths[i]);

		if (load_modules_from(volume, path) != B_OK)
			failed++;
	}

	if (failed == i) {
		// couldn't load any boot modules
		// fall back to load all modules (currently needed by the boot floppy)
		const char *paths[] = { "bus_managers", "busses/ide", "busses/scsi",
			"generic", "partitioning_systems", "drivers/bin", NULL};

		for (int32 i = 0; paths[i]; i++) {
			char path[B_FILE_NAME_LENGTH];
			snprintf(path, sizeof(path), "%s/%s", sAddonPaths[0], paths[i]);
			load_modules_from(volume, path);
		}
	}

	// and now load all partitioning and file system modules
	// needed to identify the boot volume

	if (!gBootVolume.GetBool(BOOT_VOLUME_BOOTED_FROM_IMAGE, false)) {
		// iterate over the mounted volumes and load their file system
		Partition *partition;
		if (gRoot->GetPartitionFor(volume.RootDirectory(), &partition)
				== B_OK) {
			while (partition != NULL) {
				load_module(volume, partition->ModuleName());
				partition = partition->Parent();
			}
		}
	} else {
		// The boot image should only contain the file system
		// needed to boot the system, so we just load it.
		// ToDo: this is separate from the fall back from above
		//	as this piece will survive a more intelligent module
		//	loading approach...
		char path[B_FILE_NAME_LENGTH];
		snprintf(path, sizeof(path), "%s/%s", sAddonPaths[0], "file_systems");
		load_modules_from(volume, path);
	}

	return B_OK;
}