コード例 #1
0
ファイル: task3.c プロジェクト: Denkata359/po-homework-1
int main()
{
    int arr[MAX_SYMB];
    int i;
    for( i = 0; scanf("%d", &arr[i]) != EOF; i++) {
        if(i==MAX_SYMB) break;
    }
    int lenght = i - 1;
    int inarray = 0, err = 1;
    for ( i = 0; i < MAX_SYMB && err != 0; i++ ) {
        if( is_in_bound( arr, lenght, hop(&arr[inarray])) ) {
            inarray += arr[inarray];
            if(!*hop(&arr[inarray])) {
                err = 0;
                i++;
            }
        } else {
            err = 1;
            i++;
            break;
        }
    }
    if(err == 1)printf("0\n%d", i);
    else printf("1\n%d", i);
    return 0;
}
コード例 #2
0
ファイル: task3.c プロジェクト: Valio3/po-homework-1
int main(){
	int arr[50];
	int i=0,*m,c=0,sym;
	do{
		scanf("%d",&arr[i]);
		i++;
	}while(i<6);
	sym=i;
	m=hop(&arr[0]);
	for(i=1;i<50;i++){
		if(is_in_bound(arr,50,m)==1&&m-&arr[0]<sym){
			if(arr[m-&arr[0]]==0){
				c=1;
				break;
			}
			else{
				m=hop(m);
			}
	}
		else{
			break;
		}
	}
	printf("%d\n%d", c, i);
	return 0;
}
コード例 #3
0
ファイル: task3.c プロジェクト: elsys/po-homework
int main()
{
    int arr[50];
    int lenght = 0;
    int counter = 0;
    int *ptr = &arr[0];

    while(scanf("%d", &arr[lenght]) != EOF || lenght < 50)
    {
        lenght ++;
    };
    for(;counter <= 50; counter++){

        ptr = hop(ptr);

        if(*ptr == 0){
            printf("1\n");
            printf("%d", counter);
	    break;
        };
        if(!is_in_bound(arr, lenght, ptr)){
            printf("0\n");
            printf("%d", counter);
	    break;
        };
        if(counter == 50 && *ptr != 0){
            printf("0\n");
            printf("%d", counter);
	    break;
        };
    };
return 0;
}
コード例 #4
0
ファイル: task3.c プロジェクト: Valio3/po-homework-1
int main()
{
	int arr[50],size;
	int* ptr=arr;
	int i=0,temp=0,hops=0,result=0;
	for(i=0;i<50 && scanf("%d",&temp)!=EOF;i++)
	{
		arr[i]=temp;
	}	
	size=i;
	temp=0;
	for(i=0;i<50;i++)
	{
		if(is_in_bound(arr,size,ptr)==1)
		{
			if(*ptr==0)
			{
				result=1;
				break;
			}
			ptr=hop(ptr);
			hops++;			
		}
		else
		{
			break;
		}
	}
	printf("\n%d\n%d",result,hops);
	return 0;
}
コード例 #5
0
ファイル: task3.c プロジェクト: Denkata359/po-homework-1
int main() {
    
    int arr[MAX_LENGTH], i, length, *ptr, way = 0, hops = 0;
    
    for (i = 0; scanf("%d", &arr[i]) != EOF; i++) {
        if (i == MAX_LENGTH - 1) {
            break;
        }
    }
    
    length = i + 1;
    ptr = arr;

    for (i = 0; is_in_bound(arr, length, ptr) && hops < MAX_HOPS; i += arr[i]) {
        
        hops++;
        
        if (arr[i] == 0) {
            way = 1;
            hops--;
            break;
        }
        
        ptr = hop(&arr[i]);
    }
    
    printf("%d\n%d", way, hops);
    
    return 0;
}
コード例 #6
0
ファイル: task3.c プロジェクト: Valio3/po-homework-1
int main(){

    int ground[MAX_SIZE], counter = 0, *ptr, hops = 0;
    
    while(scanf("%d", &ground[counter]) != EOF && counter++ < 50 );
    
    ptr = &ground[0];
    
    do{
    
    	if(*ptr == '0'){
    	
    		printf("1\n");
    		break;
    	
    	}
    	
    	ptr = hop(ptr);
    	
    	hops++;
    	
    	if(!is_in_bound(ground, counter, ptr) || hops > 49){
    	
    		printf("0\n");
    		break;
    	
    	}
    
    }while(1);
    
    printf("%d\n", hops);
    
    return 0;
}
コード例 #7
0
ファイル: int.c プロジェクト: vonderborch/CS460
/****************** syscall handler in C ***************************/
int kcinth()
{
   	int a,b,c,d, r;
//==> WRITE CODE TO GET get syscall parameters a,b,c,d from ustack 
    a = get_word(running->uss, running->usp + 18); // was 26
    b = get_word(running->uss, running->usp + 20); // was 28
    c = get_word(running->uss, running->usp + 22); // was 30
    d = get_word(running->uss, running->usp + 24); // was 32
	
   switch(a)
   {
       case 0 : r = kgetpid();        break;
       case 1 : r = kpd();            break;
       case 2 : r = kchname(b);       break;
       case 3 : r = kkfork();         break;
       case 4 : r = ktswitch();       break;
       case 5 : r = kkwait(b);        break;
       case 6 : r = kkexit(b);        break;
       
       case 12: r = getMyname(b);     break;
       case 20: r = hop(b);           break;

       case 90: r = getc();           break;
       case 91: r = putc(b);          break;
       case 99: kkexit(b);            break;
       default: printf("invalid syscall # : %d\n", a); 
   }

//==> WRITE CODE to let r be the return value to Umode
    put_word(r, running->uss, running->usp + 8); // was 16
    return r;
}
コード例 #8
0
ファイル: task3.c プロジェクト: Valio3/po-homework-1
int main()
{
	int i = 0, in[51] = { 0 }, size = 0, *el = 0, a = 0;
	while(1)
	{
		if(scanf("%d",&in[i]) == EOF) break;
		else i++;
	}

	el = in;
	size = i;
	i = 1;

	for(a = 0 ; a < 50 ; a++)
	{
		if(is_in_bound(in, size, el) == 0)
		{
			i = 0;
			printf("0\n");
			break;
		}
		if(*el == 0)
		{
			i = 0;
			printf("1\n");
			break;
		}
		el = hop(el);
	}

	if(i) printf("0\n");
	printf("%d\n", a);
	return 0;
}
コード例 #9
0
ファイル: task3.c プロジェクト: elsys/po-homework
int main(int argc, const char * argv[]) {

    int size = 0;
    int nums[50];


    while (scanf("%d", &nums[size]) != EOF) {
        size++;
    }

    int *ptr = nums;
    int hops = 0;
    while (1) {
        if (*ptr == 0) {
            printf("1\n");
            break;
        }
        ptr = hop(ptr);
        hops++;
        if (!is_in_bound(nums, size, ptr) || hops >= 50) {
            printf("0\n");
            break;
        }
    }

    printf("%d\n", hops);

    return 0;
}
コード例 #10
0
ファイル: frog.cpp プロジェクト: prad123/PDP_COURSEWORK2
bool CFrog::on_new_message(int source, int message_id, CActor* actor){

	if(message_id == MSG_CELL_INFO){//hoped to new cell
		m_population[m_hops%POP_CELLS] = m_recv_buffer[0];
		m_inf_level[m_hops%INF_CELLS]  = m_recv_buffer[1];

		//can spawn?
		if(m_hops >= POP_CELLS){
			float avg_pop = 0.0f;
			for(int i = 0; i < POP_CELLS; ++i) {
				avg_pop += m_population[i];
			}
			avg_pop /= POP_CELLS;

			int can_spawn = willGiveBirth(avg_pop, &m_state);
			if(can_spawn) {
			#ifdef VERBOSE
				printf("Frog %d spawning\n", m_rank);
			#endif
				//spawn(actor);
			}
		}	

		//is infected?
		if((m_infected == 0) && (m_hops >= INF_CELLS)){
			float avg_inf_level = 0.0f;
			for(int i=0; i<INF_CELLS; ++i){
				avg_inf_level += m_inf_level[i];
			}
			avg_inf_level /= INF_CELLS;
			m_infected = willCatchDisease(avg_inf_level, &m_state);
			#ifdef VERBOSE
			if(m_infected)
				printf("Frog %ld is infected\n", m_rank);
			#endif
		}

		//will die?		
		if((m_infected == 1) && (m_hops%700 == 0)){
			if(willDie(&m_state)){
				#ifdef VERBOSE
				printf("Frog %ld is dead\n", m_rank);
				#endif
				return false;//task finished
			}
		}
		
		
	} else if(message_id == MSG_NEW_FROG_BORN) { //new frog is born
		m_pos_x    = m_recv_buffer[0]; //x position
		m_pos_y    = m_recv_buffer[1]; //y position
		m_infected = m_recv_buffer[2];	//is infected?
		#ifdef VERBOSE
		printf("Frog born at position(%f,%f)\n", 
						m_pos_x, m_pos_y);
		#endif
	}
	hop(actor);//hop to new location
	return true;
}	
コード例 #11
0
ファイル: sample-11-14.cpp プロジェクト: t-sakashita/rokko
int main(int argc, char** argv) {
  std::cout.precision(10);
  options opt(argc, argv, 14);
  if (!opt.valid) std::abort();
  boost::timer tm;
  double t1 = tm.elapsed();

  // lattice structure
  int n = opt.N;
  int ibond = n;
  std::vector<int> ipair;
  for (int i = 0; i < ibond; ++i) {
    ipair.push_back(i);
    ipair.push_back((i + 1) % n);
  }

  // Hamiltonian parameters
  std::vector<double> bondwt(ibond, -1);
  std::vector<double> zrtio(ibond, 1);

  // table of configurations and Hamiltonian operator
  subspace ss(n, 0);
  hamiltonian hop(ss, ipair, bondwt, zrtio);

  // Hamiltonian matrix
  matrix_type elemnt;
  elm3(hop, elemnt);
  double t2 = tm.elapsed();
  
  std::vector<double> E;
  matrix_type v;
  int nvec = 1;
  diag(elemnt, E, v, nvec);
  double t3 = tm.elapsed();

  int ne = 4;
  std::cout << "[Eigenvalues]\n";
  for (int i = 0; i < ne; ++i) std::cout << '\t' << E[i];
  std::cout << std::endl;

  // // Do not forget to call elm3 again before calling check3
  elm3(hop, elemnt);
  check3(elemnt, v, 0);
  double t4 = tm.elapsed();
  
  std::vector<int> npair;
  npair.push_back(1);
  npair.push_back(2);
  std::vector<double> sxx(1);
  xcorr(ss, npair, v, 0, sxx);
  std::cout << "sxx: " << sxx[0] << std::endl;
  std::vector<double> szz(1);
  zcorr(ss, npair, v, 0, szz);
  std::cout << "szz: " << szz[0] << std::endl;
  double t5 = tm.elapsed();
  std::cerr << "initialize      " << (t2-t1) << " sec\n"
            << "diagonalization " << (t3-t2) << " sec\n"
            << "check           " << (t4-t3) << " sec\n"
            << "correlation     " << (t5-t4) << " sec\n";
}
コード例 #12
0
ファイル: refresh.cpp プロジェクト: ComLock/OpenTTD
/**
 * Iterate over orders starting at \a cur and \a next and refresh links
 * associated with them. \a cur and \a next can be equal. If they're not they
 * must be "neigbours" in their order list, which means \a next must be directly
 * reachable from \a cur without passing any further OT_GOTO_STATION or
 * OT_IMPLICIT orders in between.
 * @param cur Current order being evaluated.
 * @param next Next order to be checked.
 * @param flags RefreshFlags to give hints about the previous link and state carried over from that.
 */
void LinkRefresher::RefreshLinks(const Order *cur, const Order *next, uint8 flags)
{
	while (next != NULL) {

		/* If the refit cargo is CT_AUTO_REFIT, we're optimistic and assume the
		 * cargo will stay the same. The point of this method is to avoid
		 * deadlocks due to vehicles waiting for cargo that isn't being routed,
		 * yet. That situation will not occur if the vehicle is actually
		 * carrying a different cargo in the end. */
		if ((next->IsType(OT_GOTO_DEPOT) || next->IsType(OT_GOTO_STATION)) &&
				next->IsRefit() && !next->IsAutoRefit()) {
			SetBit(flags, WAS_REFIT);
			this->HandleRefit(next);
		}

		/* Only reset the refit capacities if the "previous" next is a station,
		 * meaning that either the vehicle was refit at the previous station or
		 * it wasn't at all refit during the current hop. */
		if (HasBit(flags, WAS_REFIT) && (next->IsType(OT_GOTO_STATION) || next->IsType(OT_IMPLICIT))) {
			SetBit(flags, RESET_REFIT);
		} else {
			ClrBit(flags, RESET_REFIT);
		}

		next = this->PredictNextOrder(cur, next, flags);
		if (next == NULL) break;
		Hop hop(cur->index, next->index, this->cargo);
		if (this->seen_hops->find(hop) != this->seen_hops->end()) {
			break;
		} else {
			this->seen_hops->insert(hop);
		}

		/* Don't use the same order again, but choose a new one in the next round. */
		ClrBit(flags, USE_NEXT);

		/* Skip resetting and link refreshing if next order won't do anything with cargo. */
		if (!next->IsType(OT_GOTO_STATION) && !next->IsType(OT_IMPLICIT)) continue;

		if (HasBit(flags, RESET_REFIT)) {
			this->ResetRefit();
			ClrBit(flags, RESET_REFIT);
			ClrBit(flags, WAS_REFIT);
		}

		if (cur->IsType(OT_GOTO_STATION) || cur->IsType(OT_IMPLICIT)) {
			if (cur->CanLeaveWithCargo(HasBit(flags, HAS_CARGO))) {
				SetBit(flags, HAS_CARGO);
				this->RefreshStats(cur, next);
			} else {
				ClrBit(flags, HAS_CARGO);
			}
		}

		/* "cur" is only assigned here if the stop is a station so that
		 * whenever stats are to be increased two stations can be found. */
		cur = next;
	}
}
コード例 #13
0
ファイル: BtTreeModel.cpp プロジェクト: kscottj/brewtarget
void BtTreeModel::copySelected(QList< QPair<QModelIndex, QString> > toBeCopied)
{
   while ( ! toBeCopied.isEmpty() ) 
   {
      QPair<QModelIndex,QString> thisPair = toBeCopied.takeFirst();
      QModelIndex ndx = thisPair.first;
      QString name = thisPair.second;

      switch ( type(ndx) ) 
      {
         case BtTreeItem::EQUIPMENT:
            Equipment *copyKit,  *oldKit;
            oldKit = equipment(ndx);
            copyKit = Database::instance().newEquipment(oldKit); // Create a deep copy.
            copyKit->setName(name);
            break;
         case BtTreeItem::FERMENTABLE:
            Fermentable *copyFerm, *oldFerm;
            oldFerm = fermentable(ndx);
            copyFerm = Database::instance().newFermentable(oldFerm); // Create a deep copy.
            copyFerm->setName(name);
            break;
         case BtTreeItem::HOP:
            Hop *copyHop,  *oldHop;
            oldHop = hop(ndx);
            copyHop = Database::instance().newHop(oldHop); // Create a deep copy.
            copyHop->setName(name);
            break;
         case BtTreeItem::MISC:
            Misc *copyMisc, *oldMisc;
            oldMisc = misc(ndx);
            copyMisc = Database::instance().newMisc(oldMisc); // Create a deep copy.
            copyMisc->setName(name);
            break;
         case BtTreeItem::RECIPE:
            Recipe *copyRec,  *oldRec;
            oldRec = recipe(ndx);
            copyRec = Database::instance().newRecipe(oldRec); // Create a deep copy.
            copyRec->setName(name);
            break;
         case BtTreeItem::STYLE:
            Style *copyStyle, *oldStyle;
            oldStyle = style(ndx);
            copyStyle = Database::instance().newStyle(oldStyle); // Create a deep copy.
            copyStyle->setName(name);
            break;
         case BtTreeItem::YEAST:
            Yeast *copyYeast, *oldYeast;
            oldYeast = yeast(ndx);
            copyYeast = Database::instance().newYeast(oldYeast); // Create a deep copy.
            copyYeast->setName(name);
            
            break;
         default:
            Brewtarget::logW(QString("deleteSelected:: unknown type %1").arg(type(ndx)));
      }
   }
}
コード例 #14
0
ファイル: task3.c プロジェクト: elsys/po-homework
int main()
{
    int arr[50],h=0,i=0;
    int *ptr;


    while(scanf("%d",&arr[i]) != EOF && i<50)
    {
        i=i+1;
    }



    ptr=&arr[0];

    //printf("%d\n",*ptr);

    do {

        if (*ptr==0)
        {
            printf("1\n");
            break;
        }
        ptr=hop(ptr);

        h++;

        //printf("\n %d",*ptr);



        if (is_in_bound(arr,i,ptr)==0 || h>49)
        {

            printf("0\n");
            break;
        }

        //printf("\nj=%d",j);


    } while(1);


    printf("%d\n",h);

    return 0;
}
コード例 #15
0
ファイル: task3.c プロジェクト: Denkata359/po-homework-1
int main()
{
    int m[50],i,n,*p;
    for(i=0;m[i]!=EOF;i++)
    scanf("%d",&m[i]);
    n=i-8;
    p=m;
    for(i=0;i<50 && is_in_bound(m,n,p)!=0 && *p!=0;++i)
        p=hop(p);
        if(m[i+1]==0)
            printf("1\n%d",i);
        else
            printf("0\n%d",i);
    return 0;
}
コード例 #16
0
ファイル: task3.c プロジェクト: Valio3/po-homework-1
int main()
{
	int arr[50], size, *ptr;
	int hops=0;
	int i=0, temp=0;
	for(i=0; scanf("%d", &temp)!=EOF; i++)
	{
		arr[i]=temp;
	}
	temp=0;
	size=i;
	i=0;
	ptr=&arr[0];
	while(hops!=50)
	{
		temp=0;
		temp=is_in_bound(&arr[0], size, ptr);
		if(*ptr==0 && temp==1)
		{
			temp=1;
			break;
		}
		if(temp==0)
		{
			break;
		}
		if(temp==1)
		{
			hops++;
		}
		temp=0;
		ptr=hop(ptr);
	}
	if(temp==1)
	{
		printf("1\n%d", hops);
	}
	else
	{
		printf("0\n%d", hops);
	}
	return 0;
}
コード例 #17
0
void BtTreeModel::deleteSelected(QModelIndexList victims)
{
   QModelIndexList toBeDeleted = victims; // trust me

   while ( ! toBeDeleted.isEmpty() ) 
   {
      QModelIndex ndx = toBeDeleted.takeFirst();
      switch ( type(ndx) ) 
      {
         case BtTreeItem::EQUIPMENT:
            Database::instance().remove( equipment(ndx) );
            break;
         case BtTreeItem::FERMENTABLE:
            Database::instance().remove( fermentable(ndx) );
            break;
         case BtTreeItem::HOP:
            Database::instance().remove( hop(ndx) );
            break;
         case BtTreeItem::MISC:
            Database::instance().remove( misc(ndx) );
            break;
         case BtTreeItem::RECIPE:
            Database::instance().remove( recipe(ndx) );
            break;
         case BtTreeItem::STYLE:
            Database::instance().remove( style(ndx) );
            break;
         case BtTreeItem::YEAST:
            Database::instance().remove( yeast(ndx) );
            break;
         case BtTreeItem::BREWNOTE:
            Database::instance().remove( brewNote(ndx) );
            break;
         case BtTreeItem::FOLDER:
            // This one is weird.
            toBeDeleted += allChildren(ndx);
            removeFolder(ndx);
            break;
         default:
            Brewtarget::logW(QString("deleteSelected:: unknown type %1").arg(type(ndx)));
      }
   }
}
コード例 #18
0
ファイル: task3.c プロジェクト: Denkata359/po-homework-1
int main(){
	int step,size;
	int array[50];
	int * step_hop = array;
	for(size = 0; scanf("%d",&array[size]) != EOF;size++);
	for(step = 1; step < 50; step++){
		step_hop = hop(step_hop);
		if(*step_hop == 0){
			printf("1\n%d",step);
			break;
		}
		if(!is_in_bound(array,size, step_hop)){
			printf("0\n%d",step);
			break;
		}
	}
	if(step == 49){
		printf("0\n50");
	}
}
コード例 #19
0
ファイル: task3.c プロジェクト: Valio3/po-homework-1
int main()
{
    int arr[MAX_LEN], *p, hops, flag, num, lim=0;

    num=0;
    while(scanf("%d", &arr[num]) != EOF) num++;

    flag=0;
    p=arr;
    hops=0;
    while(*p!=0 && hops<MAX_HOPS && lim<1)
    {
        p=hop(p);
        lim=is_in_bound(arr,num,p);
        hops++;
    }

    if(*p==0 && lim!=1)
    {
        flag=1;
    }
    printf("%d\n%d",flag,hops);
    return 0;
}
コード例 #20
0
ファイル: u1.c プロジェクト: JohnnySmith1/Cpts-349-Work
main()
{ 
	char name[64]; int pid, cmd;

	while(1)
	{
		pid = getpid();

		color = 0x0C;

		printf("----------------------------------------------\n");
		printf("I am proc %d in U mode: running segment=%x\n", getpid(), getcs());
		show_menu();
		printf("Command ? ");
		gets(name); 
		if (name[0]==0) 
		{
			continue;
		}

		cmd = find_cmd(name);
		switch(cmd)
		{
			case 0 : getpid();   break;
			case 1 : ps();       break;
			case 2 : chname();   break;
			case 3 : kfork();    break;
			case 4 : kswitch();  break;
			case 5 : wait();     break;
			case 6 : exit();     break;
			case 7 : hop();      break;

			default: invalid(name); break;
		}
	}
}
コード例 #21
0
bool findAP_orderedegde_dijastra(GraphTopo *p_graph, Request *p_request, int source,
		int destination, vector<int>& node_vis, vector<int>& edge_vis) {
	typedef pair<int, int> P;
	vector<int> dist((*p_graph).nodeNum, (-1));
	vector<int> hop((*p_graph).nodeNum, (-1));
	vector<int> path_node((*p_graph).nodeNum, (-1));
	vector<int> path_edge((*p_graph).nodeNum, (-1));
	priority_queue<P, vector<P>, greater<P> > que;
	unsigned int len;
	dist[source] = 0;
	hop[source] = 0;
	que.push(P(0, source));
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (dist[v] < p.first)
			continue;
		len = (*p_graph).ftopo_r_Node_c_EdgeList[v].edgeList.size();
		for (unsigned int i = 0; i < len; i++) {
			EdgeClass &e = p_graph->getithEdge(
					(*p_graph).ftopo_r_Node_c_EdgeList[v].edgeList[i]);
			if (!p_request->APMustNotPassEdges[e.id])
				continue;
			if (-1 == dist[e.to]) {
				dist[e.to] = dist[v] + e.cost;
				hop[e.to] = hop[v] + 1;
				path_node[e.to] = v;
				path_edge[e.to] = e.id;
				que.push(P(dist[e.to], e.to));
			} else {
				if (dist[e.to] > (dist[v] + e.cost)) {
					dist[e.to] = dist[v] + e.cost;
					hop[e.to] = hop[v] + 1;
					path_node[e.to] = v;
					path_edge[e.to] = e.id;
					que.push(P(dist[e.to], e.to));
				} else {
					if (dist[e.to] == (dist[v] + e.cost)) {
						if (hop[e.to] > (hop[v] + 1)) {
							hop[e.to] = hop[v] + 1;
							path_node[e.to] = v;
							path_edge[e.to] = e.id;
							que.push(P(dist[e.to], e.to));
						}
					}
				}
			}
		}
	}
	if (-1 == dist[destination]) {
		return false;
	} else {
		int next = destination;
		while (source != next) {
			if ((-1 != node_vis[next])) { //erase all edge whose out-edge is initial source node;
				return false;
			} else {
				node_vis[next] = path_node[next];
				edge_vis[next] = path_edge[next];
			}
			next = path_node[next];
		}
	}
	return true;
}
コード例 #22
0
ファイル: qm_gaussian.c プロジェクト: t-/adaptive
real call_gaussian_SH(t_commrec *cr, t_forcerec *fr, t_QMrec *qm, t_MMrec *mm,
		      rvec f[], rvec fshift[])
{
  /* a gaussian call routine intended for doing diabatic surface
   * "sliding". See the manual for the theoretical background of this
   * TSH method.
   */
  static int
    step=0;
  int
    state,i,j;
  real
    QMener=0.0;
  static  gmx_bool
    swapped=FALSE; /* handle for identifying the current PES */
  gmx_bool
    swap=FALSE; /* the actual swap */
  rvec
    *QMgrad,*MMgrad;
  char
    *buf;
  char
    *exe;

  snew(exe,30);
  sprintf(exe,"%s/%s",qm->gauss_dir,qm->gauss_exe);
  /* hack to do ground state simulations */
  if(!step){
    snew(buf,20);
    buf = getenv("STATE");
    if (buf)
      sscanf(buf,"%d",&state);
    else
      state=2;
    if(state==1)
      swapped=TRUE;
  }
  /* end of hack */


  /* copy the QMMMrec pointer */
  snew(QMgrad,qm->nrQMatoms);
  snew(MMgrad,mm->nrMMatoms);
  /* at step 0 there should be no SA */
  /*  if(!step)
   * qr->bSA=FALSE;*/
  /* temporray set to step + 1, since there is a chk start */
  write_gaussian_SH_input(step,swapped,fr,qm,mm);

  do_gaussian(step,exe);
  QMener = read_gaussian_SH_output(QMgrad,MMgrad,step,swapped,qm,mm);

  /* check for a surface hop. Only possible if we were already state
   * averaging.
   */
  if(qm->SAstep>0){
    if(!swapped){
      swap    = (step && hop(step,qm));
      swapped = swap;
    }
    else { /* already on the other surface, so check if we go back */
      swap    = (step && hop(step,qm));
      swapped =!swap; /* so swapped shoud be false again */
    }
    if (swap){/* change surface, so do another call */
      write_gaussian_SH_input(step,swapped,fr,qm,mm);
      do_gaussian(step,exe);
      QMener = read_gaussian_SH_output(QMgrad,MMgrad,step,swapped,qm,mm);
    }
  }
  /* add the QMMM forces to the gmx force array and fshift
   */
  for(i=0;i<qm->nrQMatoms;i++){
    for(j=0;j<DIM;j++){
      f[i][j]      = HARTREE_BOHR2MD*QMgrad[i][j];
      fshift[i][j] = HARTREE_BOHR2MD*QMgrad[i][j];
    }
  }
  for(i=0;i<mm->nrMMatoms;i++){
    for(j=0;j<DIM;j++){
      f[i+qm->nrQMatoms][j]      = HARTREE_BOHR2MD*MMgrad[i][j];
      fshift[i+qm->nrQMatoms][j] = HARTREE_BOHR2MD*MMgrad[i][j];
    }
  }
  QMener = QMener*HARTREE2KJ*AVOGADRO;
  fprintf(stderr,"step %5d, SA = %5d, swap = %5d\n",
	  step,(qm->SAstep>0),swapped);
  step++;
  free(exe);
  return(QMener);

} /* call_gaussian_SH */
コード例 #23
0
ファイル: sample-01_mpi.cpp プロジェクト: t-sakashita/rokko
int main(int argc, char** argv) {
  int provided;
  MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
  rokko::grid_1d g;
  if (g.get_nprocs() > 1) {
    std::cerr << "currently works only for Np = 1\n";
  }

  std::cout.precision(10);
  options opt(argc, argv, 16, solver_type::default_solver(), g.get_myrank() == 0);
  if (!opt.valid) MPI_Abort(MPI_COMM_WORLD, 1);
  boost::timer tm;
  MPI_Barrier(g.get_comm());
  double t1 = tm.elapsed();

  // lattice structure
  int n = opt.N;
  int ibond = n;
  std::vector<int> ipair;
  for (int i = 0; i < ibond; ++i) {
    ipair.push_back(i);
    ipair.push_back((i + 1) % n);
  }

  // Hamiltonian parameters
  std::vector<double> bondwt(ibond, -1);
  std::vector<double> zrtio(ibond, 1);

  // table of configurations and Hamiltonian operator
  subspace ss(n, 0);
  hamiltonian hop(ss, ipair, bondwt, zrtio);
  solver_type solver(opt.solver);
  solver.initialize(argc, argv);
  MPI_Barrier(g.get_comm());
  double t2 = tm.elapsed();
  
  // Eigenvalues
  int nev = 10;
  int blockSize = 5;
  int maxIters = 500;
  double tol = 1.0e-8;
  solver.diagonalize(hop, nev, blockSize, maxIters, tol);
  double t3 = tm.elapsed();
  
  if (g.get_myrank() == 0) {
    std::cout << "[Number of converged eigenpairs]\n\t" << solver.num_conv() << std::endl;
    // std::cout << "[Iteration number]\n\t" << itr << std::endl;
    std::cout << "[Eigenvalues]\n";
    for (int i = 0; i < solver.num_conv(); ++i) std::cout << '\t' << solver.eigenvalue(i);
    std::cout << std::endl;
  }

  // Ground-state eigenvector
  rokko::distributed_vector eigvec;
  solver.eigenvector(0, eigvec);
  if (g.get_myrank() == 0) std::cout << "[Eigenvector components (selected)]";
  std::cout << std::flush;
  MPI_Barrier(g.get_comm());
  int count = 0;
  for (int i = 12; i < ss.dimension(); i += ss.dimension()/20, ++count) {
    if (eigvec.is_gindex(i)) {
      if (count % 4 == 0) std::cout << std::endl;
      std::cout << '\t' << eigvec.get_global(i);
    }
    std::cout << std::flush;
    MPI_Barrier(g.get_comm());
  }
  if (g.get_myrank() == 0) std::cout << std::endl;
  std::cout << std::flush;
  MPI_Barrier(g.get_comm());

  // Precision check and correlation functions
  // double Hexpec = check2(mat, x, 0, v, 0);

  // std::vector<int> npair;
  // npair.push_back(1);
  // npair.push_back(2);
  // std::vector<double> sxx(1), szz(1);
  // xcorr(ss, npair, x, 0, sxx);
  // zcorr(ss, npair, x, 0, szz);
  // std::cout << "[Nearest neighbor correlation functions]\n\t" 
  //           << "sxx : " << sxx[0]
  //           << ", szz : " << szz[0] << std::endl;

  if (g.get_myrank() == 0) {
    std::cerr << "initialize      " << (t2-t1) << " sec\n"
              << "diagonalization " << (t3-t2) << " sec\n";
    // << "check           " << (t4-t3) << " sec\n"
    // << "correlation     " << (t5-t4) << " sec\n";
  }

  MPI_Finalize();
}
コード例 #24
0
bool FindCandidateBackup(GraphTopo *p_graph, Request * p_request, vector<int> &T) {
	typedef pair<int, int> P;
	vector<int> dist((*p_graph).nodeNum, (-1));
	vector<int> hop((*p_graph).nodeNum, (-1));
	vector<int> path_node((*p_graph).nodeNum, (-1));
	vector<int> path_edge((*p_graph).nodeNum, (-1));
	priority_queue<P, vector<P>, greater<P> > que;
	dist[(*p_graph).source] = 0;
	hop[(*p_graph).source] = 0;
	que.push(P(0, (*p_graph).source));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;

		if (dist[v] < p.first)
			continue;
		for (unsigned int i = 0;
				i < (*p_graph).ftopo_r_Node_c_EdgeList[v].edgeList.size();
				i++) {

			EdgeClass &e = p_graph->getithEdge(
					(*p_graph).ftopo_r_Node_c_EdgeList[v].edgeList[i]);

//			if (!A.at(e.id)) //p_request->APMustNotPassEdges[e.id])
//				continue;
			if (!p_request->BPMustNotPassEdges4AP[e.id])
				continue;
			int addcost;
			if (!p_request->BPMustNotPassEdgesRLAP[e.id]) {
				addcost = M;
			} else
				addcost = e.cost;

			if (-1 == dist[e.to]) {
				dist[e.to] = dist[v] + addcost;			//e.cost;
				hop[e.to] = hop[v] + 1;
				path_node[e.to] = v;
				path_edge[e.to] = e.id;
				que.push(P(dist[e.to], e.to));
			} else {
				if (dist[e.to] > (dist[v] + addcost)) {
					dist[e.to] = dist[v] + addcost;
					hop[e.to] = hop[v] + 1;
					path_node[e.to] = v;
					path_edge[e.to] = e.id;
					que.push(P(dist[e.to], e.to));
				} else {
					if (dist[e.to] == (dist[v] + addcost)) {
						if (hop[e.to] > (hop[v] + 1)) {
							dist[e.to] = dist[v] + addcost;
							hop[e.to] = hop[v] + 1;
							path_node[e.to] = v;
							path_edge[e.to] = e.id;
							que.push(P(dist[e.to], e.to));
						}
					}
				}
			}
		}
	}

	if (-1 == dist[(*p_graph).destination]) {
		return false;
	} else {
		int now;
		int next;

		now = (*p_graph).destination;
		vector<int> midnode;
		vector<int> midedge;
		next = path_node[now];
		midnode.push_back(now);

		while (next != -1) {
			midnode.push_back(next);
			midedge.push_back(path_edge[now]);
			if (!p_request->BPMustNotPassEdgesRLAP[path_edge[now]])
				T.push_back(p_graph->getithEdge(path_edge[now]).ithsrlg);
			(*p_request).BPCostSum += p_graph->getithEdge(path_edge[now]).cost;
			now = next;
			next = path_node[now];
		}
		for (int k = (midnode.size() - 1); k >= 0; k--) {
			p_request->BP_PathNode.push_back(midnode[k]);
		}
		for (int k = (midedge.size() - 1); k >= 0; k--) {
			p_request->BP_PathEdge.push_back(midedge[k]);
		}

		return true;
	}
	return false;
}
コード例 #25
0
void BtTreeModel::copySelected(QList< QPair<QModelIndex, QString> > toBeCopied)
{
   bool failed = false;
   while ( ! toBeCopied.isEmpty() ) 
   {
      QPair<QModelIndex,QString> thisPair = toBeCopied.takeFirst();
      QModelIndex ndx = thisPair.first;
      QString name = thisPair.second;

      switch ( type(ndx) ) 
      {
         case BtTreeItem::EQUIPMENT:
            Equipment *copyKit,  *oldKit;
            oldKit = equipment(ndx);
            copyKit = Database::instance().newEquipment(oldKit); // Create a deep copy.
            if ( copyKit) 
               copyKit->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::FERMENTABLE:
            Fermentable *copyFerm, *oldFerm;
            oldFerm = fermentable(ndx);
            copyFerm = Database::instance().newFermentable(oldFerm); // Create a deep copy.
            if ( copyFerm )
               copyFerm->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::HOP:
            Hop *copyHop,  *oldHop;
            oldHop = hop(ndx);
            copyHop = Database::instance().newHop(oldHop); // Create a deep copy.
            if ( copyHop )
               copyHop->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::MISC:
            Misc *copyMisc, *oldMisc;
            oldMisc = misc(ndx);
            copyMisc = Database::instance().newMisc(oldMisc); // Create a deep copy.
            if ( copyMisc )
               copyMisc->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::RECIPE:
            Recipe *copyRec,  *oldRec;
            oldRec = recipe(ndx);
            copyRec = Database::instance().newRecipe(oldRec); // Create a deep copy.
            if ( copyRec )
               copyRec->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::STYLE:
            Style *copyStyle, *oldStyle;
            oldStyle = style(ndx);
            copyStyle = Database::instance().newStyle(oldStyle); // Create a deep copy.
            if ( copyStyle )
               copyStyle->setName(name);
            else 
               failed = true;
            break;
         case BtTreeItem::YEAST:
            Yeast *copyYeast, *oldYeast;
            oldYeast = yeast(ndx);
            copyYeast = Database::instance().newYeast(oldYeast); // Create a deep copy.
            if ( copyYeast )
               copyYeast->setName(name);
            else 
               failed = true;
            break;
         default:
            Brewtarget::logW(QString("copySelected:: unknown type %1").arg(type(ndx)));
      }
      if ( failed ) {
         QMessageBox::warning(0,
                              tr("Could not copy"), 
                              tr("There was an unexpected error creating %1").arg(name));
         return;
      }
   }
}
コード例 #26
0
bool ShortestPath(GraphTopo *p_graph, Request * p_request, vector<bool>&A) {
	typedef pair<int, int> P;
	vector<int> dist((*p_graph).nodeNum, (-1));
	vector<int> hop((*p_graph).nodeNum, (-1));
	vector<int> path_node((*p_graph).nodeNum, (-1));
	vector<int> path_edge((*p_graph).nodeNum, (-1));
	priority_queue<P, vector<P>, greater<P> > que;
	dist[(*p_graph).source] = 0;
	hop[(*p_graph).source] = 0;
	que.push(P(0, (*p_graph).source));

	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;

		if (dist[v] < p.first)
			continue;
		for (unsigned int i = 0;
				i < (*p_graph).ftopo_r_Node_c_EdgeList[v].edgeList.size();
				i++) {

			EdgeClass &e = p_graph->getithEdge(
					(*p_graph).ftopo_r_Node_c_EdgeList[v].edgeList[i]);

			if (!A.at(e.id)) //p_request->APMustNotPassEdges[e.id])
				continue;
			if (-1 == dist[e.to]) {
				dist[e.to] = dist[v] + e.cost;
				hop[e.to] = hop[v] + 1;
				path_node[e.to] = v;
				path_edge[e.to] = e.id;
				que.push(P(dist[e.to], e.to));
			} else {
				if (dist[e.to] > (dist[v] + e.cost)) {
					dist[e.to] = dist[v] + e.cost;
					hop[e.to] = hop[v] + 1;
					path_node[e.to] = v;
					path_edge[e.to] = e.id;
					que.push(P(dist[e.to], e.to));
				} else {
					if (dist[e.to] == (dist[v] + e.cost)) {
						if (hop[e.to] > (hop[v] + 1)) {
							dist[e.to] = dist[v] + e.cost;
							hop[e.to] = hop[v] + 1;
							path_node[e.to] = v;
							path_edge[e.to] = e.id;
							que.push(P(dist[e.to], e.to));
						}
					}
				}
			}
		}
	}

	if (-1 == dist[(*p_graph).destination]) {
		return false;
	} else {
		int now;
		int next;

		now = (*p_graph).destination;
		vector<int> midnode;
		vector<int> midedge;
		next = path_node[now];
		midnode.push_back(now);

		p_request->APSrlgs.clear(); //
		while (next != -1) {
			//			(*p_request).AP_PathNode.push_back(next);
			//			(*p_request).AP_PathEdge.push_back(path_edge[now]);
			midnode.push_back(next);
			midedge.push_back(path_edge[now]);
			(*p_request).BPMustNotPassEdges4AP[path_edge[now]] = false;
			if (-1 != p_graph->getithEdge(path_edge[now]).ithsrlg)
				(*p_request).APSrlgs.push_back(
						p_graph->getithEdge(path_edge[now]).ithsrlg);
			now = next;
			next = path_node[now];
		}
		for (int k = (midnode.size() - 1); k >= 0; k--) {
			p_request->AP_PathNode.push_back(midnode[k]);
		}
		for (int k = (midedge.size() - 1); k >= 0; k--) {
			p_request->AP_PathEdge.push_back(midedge[k]);
		}

		(*p_request).APCostSum = dist[(*p_graph).destination];
		(*p_request).APHopSum = hop[(*p_graph).destination];

		sort(p_request->APSrlgs.begin(), p_request->APSrlgs.end());
		vector<int>::iterator pos;
		pos = unique(p_request->APSrlgs.begin(), p_request->APSrlgs.end());
		p_request->APSrlgs.erase(pos, p_request->APSrlgs.end());

		for (unsigned int i = 0; i < (*p_request).APSrlgs.size(); i++) {
			int srlg = (*p_request).APSrlgs[i];
			for (unsigned int j = 0;
					j < (*p_graph).srlgGroups[srlg].srlgMember.size(); j++) {
				int srlgmem = (*p_graph).srlgGroups[srlg].srlgMember[j];
				if ((*p_request).BPMustNotPassEdges4AP[srlgmem]
						&& (*p_request).BPMustNotPassEdgesRLAP[srlgmem]) {
					(*p_request).BPMustNotPassEdgesRLAP[srlgmem] = false;
					p_request->RLAP_PathEdge.push_back(srlgmem);
				}
			}
		}

		return true;
	}
}