bool SetCoveringSolution::greedyCover() {
	if(coveredRows == SetCoveringDecoder::nrows) { return false; }

	// Initialize heap with columnCount values:
	BinaryHeap< double >* heap = new BinaryHeap< double >(SetCoveringDecoder::ncolumns);
	for(unsigned j = 0; j < SetCoveringDecoder::ncolumns; ++j) {
		if(rowsCoveredByCol[j] > 0) {
			heap->insert(j, - double(rowsCoveredByCol[j] / SetCoveringDecoder::columnCosts[j]));
		}
	}

	while(coveredRows < SetCoveringDecoder::nrows) {
		const unsigned greedyCol = heap->extractMin();	// Get best column from heap

		openColumn(greedyCol, &heap);	// Open it
	}

	delete heap;
	return isFeasible();
}
SetCoveringSolution::SetCoveringSolution(const std::vector< double >& chromosome,
		const bool runCover, const bool runUncover, const bool runOneOPT, const double cutoff) :
		cost(0.0),
		coveredRows(0),
		openedColumns(0),
		colsCoveringRow(SetCoveringDecoder::nrows, 0),
		selectedColumns(SetCoveringDecoder::ncolumns, false),
		rowsCoveredByCol(SetCoveringDecoder::rowsCoveredByColumn) {
	// First, open all columns indicated by the chromosome:
	for(unsigned j = 0; j < chromosome.size(); ++j) {
		if(chromosome[j] < cutoff || rowsCoveredByCol[j] == 0) { continue; }
		openColumn(j, 0);	// Open it
	}

	if(runCover && isFeasible() == false) { greedyCover(); }

	if(runUncover) { greedyUncover(); }

	if(runOneOPT) { oneOPT(); }
}
Esempio n. 3
0
greedyCover(int p)
{
	
	

	//preprocessing();	
	
	int run =1;
	
	while(covercount<M)
	{

		

		maxpole = findMax();

		selectPole(maxpole);
		
		if (run==1)
		{
			if (p==1)
			{
		
				if (covercount> M/2)
				{
					preprocessing();
					run =0;
				}
			}
		}
	
	}


	int c = cleanpoles();

	int value = CountPoles();

	printf("value %d, feasible? %d, cleanedup any poles? %d \n", value, isFeasible(), c);
}
Esempio n. 4
0
bool SquareDomainSquareHole::isFeasible(State *x) {
	if (isFeasible(x, Pursuer))
		return isFeasible(x, Evader);

	return false;
}
unsigned SetCoveringSolution::getOpenedColumns() const {
	return (isFeasible() ? openedColumns : SetCoveringDecoder::ncolumns);
}