예제 #1
0
파일: guiQuad.cpp 프로젝트: amintz/M1.0
//----------------------------------------------------
bool guiQuad::updatePoint(float x, float y, float offsetX, float offsetY, float width, float height){
	
	//nothing to update
	if(selected == -1) return false;
	
	if(width == 0 || height == 0){
		//dangerous so we ignore :)
		return false;
	}  
	
	if( x < offsetX ) 			x = offsetX;
	if( x > offsetX + width ) 	x = offsetX + width;
	if( y < offsetY ) 			y = offsetY;
	if( y > offsetY + height) 	y = offsetY + height;
	
	//lets get it in range x(0 - width) y(0 - height)
	float px = x - offsetX;
	float py = y - offsetY;
				
	//now get in 0-1 range
	px /= width;
	py /= height;
	
	srcZeroToOne[selected].x 	= px;
	srcZeroToOne[selected].y 	= py;	
	
	srcScaled[selected].x		= px;
	srcScaled[selected].y		= py;
	
	anchorPoint.x = (least(srcZeroToOne[1].x, srcZeroToOne[2].x) + greatest(srcZeroToOne[0].x, srcZeroToOne[3].x))/2;
	anchorPoint.y = (least(srcZeroToOne[2].y, srcZeroToOne[3].y) + greatest(srcZeroToOne[0].y, srcZeroToOne[1].y))/2;
	
	return true;
}
예제 #2
0
파일: guiQuad.cpp 프로젝트: amintz/M1.0
//----------------------------------------------------
void guiQuad::loadSettings(){
	
	string str;
	
	
	for(int i = 0; i < 4; i++){
		
		//These two lines give us:
		// "QUAD_SRC_0"
		// "QUAD_SRC_1" etc...
								
		str = quadName;
		str += ofToString(i);									
																						
		srcZeroToOne[i].x = xml.getValue(str+"_X", srcZeroToOne[i].x);
		srcZeroToOne[i].y = xml.getValue(str+"_Y", srcZeroToOne[i].y);		
		
		if(srcZeroToOne[i].x > 1) srcZeroToOne[i].x = 1;
		if(srcZeroToOne[i].y > 1) srcZeroToOne[i].y = 1;
									
	}
	
	anchorPoint.x = (least(srcZeroToOne[1].x, srcZeroToOne[2].x) + greatest(srcZeroToOne[0].x, srcZeroToOne[3].x))/2;
	anchorPoint.y = (least(srcZeroToOne[2].y, srcZeroToOne[3].y) + greatest(srcZeroToOne[0].y, srcZeroToOne[1].y))/2;
				
}
예제 #3
0
파일: guiQuad.cpp 프로젝트: amintz/M1.0
//----------------------------------------------------
//these should be in the range x(0-maxX) y(0-maxH) 
//with 	width  = maxW
//		height = maxH 
void guiQuad::setQuadPoints( ofxPoint2f * inPts ){
		
	for(int i = 0; i < 4; i++){
		srcZeroToOne[i].x	= inPts[i].x;
		srcZeroToOne[i].y	= inPts[i].y;
		
		if(srcZeroToOne[i].x > 1) srcZeroToOne[i].x = 1;
		if(srcZeroToOne[i].y > 1) srcZeroToOne[i].y = 1;
	}
	
	anchorPoint.x = (least(srcZeroToOne[1].x, srcZeroToOne[2].x) + greatest(srcZeroToOne[0].x, srcZeroToOne[3].x))/2;
	anchorPoint.y = (least(srcZeroToOne[2].y, srcZeroToOne[3].y) + greatest(srcZeroToOne[0].y, srcZeroToOne[1].y))/2;
}
예제 #4
0
파일: ckheap.C 프로젝트: davidheryanto/sc14
void minHeap::update(int index) {
    int parent = (index-1)/2;
                                                                                
    if((index != 0) && h[index].info->load < h[parent].info->load) {
      swap(parent,index);
      update(parent);
    }
                                                                                
    int c1 = 2*index+1;
    int c2 = 2*index+2;
                                                                                
    if(c2<numElements()){
      int smaller = least(index,c1,c2);
      if(smaller != index){
        swap(smaller,index);
        update(smaller);
        return;
      }
    }
    if(c1<numElements() && h[c1].info->load < h[index].info->load) {
      swap(c1,index);
      update(c1);
      return;
    }
}
예제 #5
0
파일: tsp.c 프로젝트: dysoco/cosmos
void tsp(int city)
{
	int ncity;
	visited[city] = 1;
	printf("%d ->",city);
	ncity = least(city);
	if(ncity == 999)
	{
		cost += a[city][1];
		printf("1\n");
		return;
	}
	tsp(ncity);
}
예제 #6
0
  void mincost(int city)
  {
  int i,ncity;
  visited[city]=1;
  printf("%d->",city);
  ncity=least(city);
  if(ncity==999)
  {
  ncity=1;
  printf("%d",ncity);
  cost+=a[city][ncity];
  return;
  }
  mincost(ncity);

  }
예제 #7
0
void TQueue::move_least(double tnew) {
	TQItem* b = least();
	if (b) {
		b->t_ = tnew;
		TQItem* nl = sphead(sptree_);
		if (nl) {
			if (tnew <= nl->t_ && tnew <= q2least_t()) {
				;
			}else if (nl->t_ <= q2least_t()) {
				least_ = spdeq(&sptree_->root);
				sp1enq(b);
			}else{
				least_ = spdeq(&sptree2_->root);
				sp1enq(b);
			}
		}else if (tnew > q2least_t()) {
			least_ = spdeq(&sptree2_->root);
			sp1enq(b);
		}
	}
}
예제 #8
0
파일: guiQuad.cpp 프로젝트: amintz/M1.0
bool guiQuad::updatePoint(float x, float y, float offsetX, float offsetY, float width, float height, bool noDistorsion){
	
	if(!noDistorsion) {
		updatePoint(x, y, offsetX, offsetY, width, height);
	} else {
		
		getScaledQuadPoints(width, height);
		
		//nothing to update
		if(selected == -1) return false;
		
		if(width == 0 || height == 0){
			//dangerous so we ignore :)
			return false;
		}  
		
		if( x < offsetX ) 			x = offsetX;
		if( x > offsetX + width ) 	x = offsetX + width;
		if( y < offsetY ) 			y = offsetY;
		if( y > offsetY + height) 	y = offsetY + height;
		
		//lets get it in range x(0 - width) y(0 - height)
		float px = x - offsetX;
		float py = y - offsetY;
		
		if (!diag_v){
			py = diag_a*px + diag_b;
			if (py < 0) { py = 0; px = ((py - diag_b)/diag_a); }
			else if (py > height) { py = height; px = ((py - diag_b)/diag_a); }
		} else {
			px = selX;
			if (px < 0) { px = 0; py = diag_b; }
			else if (px > width) { px = width; py = diag_a * width + diag_b; }
		}
		
		cout << "px = " << px << endl;
		cout << "py = " << py << endl;
		
		if (selected == 0) {
			if (sideA_v == -1) {
				sideA_b = py - (sideA_m * px);
				cout << "sideA_b = " << sideA_b << endl;
				if (sideB_v == -1) {
					float temp_x;
					if (sideB_m < 0 || sideB_m > 1) {
						temp_x= (((sideA_m * temp_x) + sideA_b - sideB_b) / sideB_m) / width;
					} else {
						temp_x= (((sideB_m * temp_x) + sideB_b - sideA_b) / sideA_m) / width;
					}
					srcZeroToOne[1].x = temp_x;
					srcZeroToOne[1].y = ((sideA_m * (srcZeroToOne[1].x * width)) + sideA_b)/height;
				} else {
					srcZeroToOne[1].y = ((sideA_m * (srcZeroToOne[1].x * width)) + sideA_b) / height;
				}
			} else {
				srcZeroToOne[1].x = px/width;
				srcZeroToOne[1].y = ((sideB_m * px) + sideB_b) / height;
			}
			
			if (sideD_v == -1) {
				sideD_b = py - (sideD_m * px);
				cout << "sideD_b = " << sideD_b << endl;
				if (sideC_v == -1) {
					float temp_x;
					if (sideC_m < 0 || sideC_m > 1) {
						temp_x = (((sideD_m * temp_x) + sideD_b - sideC_b) / sideC_m) / width;
					} else {
						temp_x = (((sideC_m * temp_x) + sideC_b - sideD_b) / sideD_m) / width;
					}
					srcZeroToOne[3].x = temp_x;
					cout << "3x = " << temp_x * width << endl;
					srcZeroToOne[3].y = ((sideD_m * (srcZeroToOne[3].x * width)) + sideD_b)/height;
					cout << "3y = " << srcZeroToOne[3].y * height << endl;
				} else {
					srcZeroToOne[3].y = ((sideD_m * (srcZeroToOne[3].x * width)) + sideD_b) / height;
				}
			} else {
				srcZeroToOne[3].x = px/width;
				srcZeroToOne[3].y = ((sideC_m * px) + sideC_b) / height;
				
			}
			
			if (srcZeroToOne[1].x < 0) { srcZeroToOne[1].x = 0; }
			else if (srcZeroToOne[1].x > 1) { srcZeroToOne[1].x = 1; }
			if (srcZeroToOne[1].y < 0) { srcZeroToOne[1].y = 0; }
			else if (srcZeroToOne[1].y > 1) { srcZeroToOne[1].y = 1; }
			
			if (srcZeroToOne[3].x < 0) { srcZeroToOne[3].x = 0; }
			else if (srcZeroToOne[3].x > 1) { srcZeroToOne[3].x = 1; }
			if (srcZeroToOne[3].y < 0) { srcZeroToOne[3].y = 0; }
			else if (srcZeroToOne[3].y > 1) { srcZeroToOne[3].y = 1; }
			
		}
			
		
		//now get in 0-1 range
		px /= width;;
		py /= height;
		
		srcZeroToOne[selected].x 	= px;
		srcZeroToOne[selected].y 	= py;
		
		anchorPoint.x = (least(srcZeroToOne[1].x, srcZeroToOne[2].x) + greatest(srcZeroToOne[0].x, srcZeroToOne[3].x))/2;
		anchorPoint.y = (least(srcZeroToOne[2].y, srcZeroToOne[3].y) + greatest(srcZeroToOne[0].y, srcZeroToOne[1].y))/2;		
	
	}
	
	return true;
}
int main(int argc, char* argv[])
{
    if (argc < 3)
    {
        std::cout << "Usage: " << argv[0] << " [n in MiB]"
            #if defined(STXXL_PARALLEL)
            << " [p threads]"
            #endif
            << std::endl;
        return -1;
    }

    STXXL_MSG("----------------------------------------");

    stxxl::config::get_instance();
    std::string Flags = std::string("")
#if STXXL_CHECK_ORDER_IN_SORTS
                        + " STXXL_CHECK_ORDER_IN_SORTS"
#endif
#ifdef NDEBUG
                        + " NDEBUG"
#endif
#if TINY_PQ
                        + " TINY_PQ"
#endif
#if MANUAL_PQ
                        + " MANUAL_PQ"
#endif
#if SIDE_PQ
                        + " SIDE_PQ"
#endif
#if STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL
                        + " STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL"
#endif
#if STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL
                        + " STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL"
#endif
#if STXXL_PARALLEL_PQ_MULTIWAY_MERGE_DELETE_BUFFER
                        + " STXXL_PARALLEL_PQ_MULTIWAY_MERGE_DELETE_BUFFER"
#endif
    ;
    STXXL_MSG("Flags:" << Flags);

    unsigned long megabytes = atoi(argv[1]);
#if defined(STXXL_PARALLEL_MODE)
    int num_threads = atoi(argv[2]);
    STXXL_MSG("Threads: " << num_threads);

    omp_set_num_threads(num_threads);
    __gnu_parallel::_Settings parallel_settings(__gnu_parallel::_Settings::get());
    parallel_settings.sort_algorithm = __gnu_parallel::QS_BALANCED;
    parallel_settings.sort_splitting = __gnu_parallel::SAMPLING;
    parallel_settings.sort_minimal_n = 1000;
    parallel_settings.sort_mwms_oversampling = 10;

    parallel_settings.merge_splitting = __gnu_parallel::SAMPLING;
    parallel_settings.merge_minimal_n = 1000;
    parallel_settings.merge_oversampling = 10;

    parallel_settings.multiway_merge_algorithm = __gnu_parallel::LOSER_TREE;
    parallel_settings.multiway_merge_splitting = __gnu_parallel::EXACT;
    parallel_settings.multiway_merge_oversampling = 10;
    parallel_settings.multiway_merge_minimal_n = 1000;
    parallel_settings.multiway_merge_minimal_k = 2;
    __gnu_parallel::_Settings::set(parallel_settings);
#endif

    const stxxl::unsigned_type mem_for_queue = 512 * mega;
    const stxxl::unsigned_type mem_for_pools = 512 * mega;

#if TINY_PQ
    stxxl::STXXL_UNUSED(mem_for_queue);
    const unsigned BufferSize1 = 32;               // equalize procedure call overheads etc.
    const unsigned N = (1 << 9) / sizeof(my_type); // minimal sequence length
    const unsigned IntKMAX = 8;                    // maximal arity for internal mergersq
    const unsigned IntLevels = 2;                  // number of internal levels
    const unsigned BlockSize = (4 * mega);
    const unsigned ExtKMAX = 8;                    // maximal arity for external mergers
    const unsigned ExtLevels = 2;                  // number of external levels
    typedef stxxl::priority_queue<
            stxxl::priority_queue_config<
                my_type,
                my_cmp,
                BufferSize1,
                N,
                IntKMAX,
                IntLevels,
                BlockSize,
                ExtKMAX,
                ExtLevels
                >
            > pq_type;
#elif MANUAL_PQ
    stxxl::STXXL_UNUSED(mem_for_queue);
    const unsigned BufferSize1 = 32;                    // equalize procedure call overheads etc.
    const unsigned N = (1 << 20) / sizeof(my_type);     // minimal sequence length
    const unsigned IntKMAX = 16;                        // maximal arity for internal mergersq
    const unsigned IntLevels = 2;                       // number of internal levels
    const unsigned BlockSize = (4 * mega);
    const unsigned ExtKMAX = 32;                        // maximal arity for external mergers
    const unsigned ExtLevels = 2;                       // number of external levels
    typedef stxxl::priority_queue<
            stxxl::priority_queue_config<
                my_type,
                my_cmp,
                BufferSize1,
                N,
                IntKMAX,
                IntLevels,
                BlockSize,
                ExtKMAX,
                ExtLevels
                >
            > pq_type;
#else
    const stxxl::uint64 volume = stxxl::uint64(200000) * mega;     // in bytes
    typedef stxxl::PRIORITY_QUEUE_GENERATOR<my_type, my_cmp, mem_for_queue, volume / sizeof(my_type) / 1024 + 1> gen;
    typedef gen::result pq_type;
//         BufferSize1 = Config::BufferSize1,
//         N = Config::N,
//         IntKMAX = Config::IntKMAX,
//         IntLevels = Config::IntLevels,
//         ExtLevels = Config::ExtLevels,
//         Levels = Config::IntLevels + Config::ExtLevels,
//         BlockSize = Config::BlockSize,
//         ExtKMAX = Config::ExtKMAX

/*  STXXL_MSG ( "Blocks fitting into internal memory m: "<<gen::m );
  STXXL_MSG ( "X : "<<gen::X );  //maximum number of internal elements //X = B * (settings::k - m) / settings::E,
  STXXL_MSG ( "Expected internal memory consumption: "<< (gen::EConsumption / 1048576) << " MiB");*/
#endif
    STXXL_MSG("Internal arity: " << pq_type::IntKMAX);
    STXXL_MSG("N : " << pq_type::N); //X / (AI * AI)
    STXXL_MSG("External arity: " << pq_type::ExtKMAX);
    STXXL_MSG("Block size B: " << pq_type::BlockSize);
    //EConsumption = X * settings::E + settings::B * AE + ((MaxS_ / X) / AE) * settings::B * 1024

    STXXL_MSG("Data type size: " << sizeof(my_type));
    STXXL_MSG("");

    stxxl::stats_data sd_start(*stxxl::stats::get_instance());
    stxxl::timer Timer;
    Timer.start();

    pq_type p(mem_for_pools / 2, mem_for_pools / 2);
    stxxl::int64 nelements = stxxl::int64(megabytes * mega / sizeof(my_type)), i;

    STXXL_MSG("Internal memory consumption of the priority queue: " << p.mem_cons() << " B");
    STXXL_MSG("Peak number of elements (n): " << nelements);
    STXXL_MSG("Max number of elements to contain: " << (stxxl::uint64(pq_type::N) * pq_type::IntKMAX * pq_type::IntKMAX * pq_type::ExtKMAX * pq_type::ExtKMAX));
    srand(5);
    my_cmp cmp;
    my_key_type r, sum_input = 0, sum_output = 0;
    my_type least(0), last_least(0);

    const my_key_type modulo = 0x10000000;

#if SIDE_PQ
    std::priority_queue<my_type, std::vector<my_type>, my_cmp> side_pq;
#endif

    my_type side_pq_least;

    STXXL_MSG("op-sequence(monotonic pq): ( push, pop, push ) * n");
    for (i = 0; i < nelements; ++i)
    {
        if ((i % mega) == 0)
            STXXL_MSG(
                std::fixed << std::setprecision(2) << std::setw(5)
                           << (100.0 * (double)i / (double)nelements) << "% "
                           << "Inserting element " << i << " top() == " << least.key << " @ "
                           << std::setprecision(3) << Timer.seconds() << " s"
                           << std::setprecision(6) << std::resetiosflags(std::ios_base::floatfield));

        //monotone priority queue
        r = least.key + rand() % modulo;
        sum_input += r;
        p.push(my_type(r));
#if SIDE_PQ
        side_pq.push(my_type(r));
#endif

        least = p.top();
        sum_output += least.key;
        p.pop();
#if SIDE_PQ
        side_pq_least = side_pq.top();
        side_pq.pop();
        if (!(side_pq_least == least))
            STXXL_MSG("Wrong result at  " << i << "  " << side_pq_least.key << " != " << least.key);
#endif

        if (cmp(last_least, least))
        {
            STXXL_MSG("Wrong order at  " << i << "  " << last_least.key << " > " << least.key);
        }
        else
            last_least = least;

        r = least.key + rand() % modulo;
        sum_input += r;
        p.push(my_type(r));
#if SIDE_PQ
        side_pq.push(my_type(r));
#endif
    }
    Timer.stop();
    STXXL_MSG("Time spent for filling: " << Timer.seconds() << " s");

    STXXL_MSG("Internal memory consumption of the priority queue: " << p.mem_cons() << " B");
    stxxl::stats_data sd_middle(*stxxl::stats::get_instance());
    std::cout << sd_middle - sd_start;
    Timer.reset();
    Timer.start();

    STXXL_MSG("op-sequence(monotonic pq): ( pop, push, pop ) * n");
    for (i = 0; i < (nelements); ++i)
    {
        assert(!p.empty());

        least = p.top();
        sum_output += least.key;
        p.pop();
#if SIDE_PQ
        side_pq_least = side_pq.top();
        side_pq.pop();
        if (!(side_pq_least == least))
        {
            STXXL_VERBOSE1("" << side_pq_least << " != " << least);
        }
#endif
        if (cmp(last_least, least))
        {
            STXXL_MSG("Wrong result at " << i << "  " << last_least.key << " > " << least.key);
        }
        else
            last_least = least;

        r = least.key + rand() % modulo;
        sum_input += r;
        p.push(my_type(r));
#if SIDE_PQ
        side_pq.push(my_type(r));
#endif

        least = p.top();
        sum_output += least.key;
        p.pop();
#if SIDE_PQ
        side_pq_least = side_pq.top();
        side_pq.pop();
        if (!(side_pq_least == least))
        {
            STXXL_VERBOSE1("" << side_pq_least << " != " << least);
        }
#endif
        if (cmp(last_least, least))
        {
            STXXL_MSG("Wrong result at " << i << "  " << last_least.key << " > " << least.key);
        }
        else
            last_least = least;

        if ((i % mega) == 0)
            STXXL_MSG(
                std::fixed << std::setprecision(2) << std::setw(5)
                           << (100.0 * (double)i / (double)nelements) << "% "
                           << "Popped element " << i << " == " << least.key << " @ "
                           << std::setprecision(3) << Timer.seconds() << " s"
                           << std::setprecision(6) << std::resetiosflags(std::ios_base::floatfield));
    }
    STXXL_MSG("Last element " << i << " popped");
    Timer.stop();

    if (sum_input != sum_output)
        STXXL_MSG("WRONG sum! " << sum_input << " - " << sum_output << " = " << (sum_output - sum_input) << " / " << (sum_input - sum_output));

    STXXL_MSG("Time spent for removing elements: " << Timer.seconds() << " s");
    STXXL_MSG("Internal memory consumption of the priority queue: " << p.mem_cons() << " B");
    std::cout << stxxl::stats_data(*stxxl::stats::get_instance()) - sd_middle;
    std::cout << *stxxl::stats::get_instance();

    assert(sum_input == sum_output);
}
예제 #10
0
void main()
{
		int ver,i,j,s,k,minval,p1[10],sv,ev,ctr;
		clrscr();

		printf("\n Enter Number Of Vertex :");
		scanf("%d",&ver);

		a=(int **)malloc(sizeof(int)*ver*ver);
		d=(int *)malloc(sizeof(int)*ver);
		p=(int *)malloc(sizeof(int)*ver);
		l=(int *)malloc(sizeof(int)*ver);
		visited=(int *)malloc(sizeof(int)*ver);

		for(i=1;i<=ver;i++)
		{
			*(a+i)=(int *)malloc(sizeof(int)*ver);
				visited[i]=0;
		}

		for(i=1;i<=ver;i++)
		{
			for(j=1;j<=ver;j++)
				{
					printf("a[%d][%d] :",i,j);
						scanf("%d",&a[i][j]);
				}
				printf("\n");
		}

		printf("\n Enter Source :");
		scanf("%d",&s);


		for(i=1;i<=ver;i++)
		{
			d[i]=a[s][i];
		}


		for(i=1;i<=ver;i++)
		{
			if(d[i]==0 || d[i]==99)
				{
					p[i]=0;
				}
				else
				{
					p[i]=s;
				}
		}

		for(i=1;i<=ver;i++)
		{
			if(p[i]!=0)
			{
				l[++top]=i;
			}
		}

		while(top!=0)
		{
			i=least(l);
			visited[i]=1;
			j=0;

				for(k=(j+1);k<=ver;k++)
				{
					if(a[i][k]!=0 && a[i][k]!=99)
					 {
						j=k;
						minval=mins(d[j],(d[i]+a[i][j]));
						if(d[j]!=minval)
						{
							d[j]=minval;
							p[j]=i;
						}
						if(visited[j]!=1)
							l[++top]=j;
					 }


				}
		}

		for(i=1;i<=ver;i++)
		{
			printf("\n Distance From 1 to %5d : %5d" ,i,d[i]);
		}
		printf("\n\n");

		for(i=1;i<=ver;i++)
		{
			printf("\n\n Path From 1 to %5d \n\n",i);
			path(i);
		}

getch();
}