Beispiel #1
0
void createListProbSwitch(xmlNode *node, tbranch_switch_node *switch_node)
{
	int qtcases, i;
	xmlNode *current;

	qtcases = countElement(node, "probability");
	if (qtcases > 0){
		switch_node->prob_cases = (trange_probability *) malloc(sizeof(trange_probability) * qtcases);
		switch_node->qtcases = qtcases;
		current = node->children;
		i=0;
		while(current)
		{
			if (!strcmp((char *)current->name, "probability")){
				switch_node->prob_cases[i].prob_start = getAttrDbl(current, "start");
				switch_node->prob_cases[i].prob_finish = getAttrDbl(current, "finish");
				start_range = getAttrDbl(current, "start-range");
				end_range = getAttrDbl(current, "end-range");
				step = getAttrDbl(current, "step");

				i++;
			}
			current = current->next;
		}
	}

}
Beispiel #2
0
void addPriority(char nama[], int prior, queue *Q){
	if ((*Q).first!=NULL){
		elemen *prev,*elmt = (*Q).first;

		int i=1, stop=0;
		while(elmt!=NULL && stop==0){
			if (countElement(*Q)<prior){
				add(nama, Q);
				stop=1;		
			}else if (i==prior){
				stop=1;
				elemen *baru;
				baru = (elemen *) malloc (sizeof(elemen));
				strcpy(baru->elmt.nama,nama);
				
				if (elmt==(*Q).first)
				{
					baru->next = (*Q).first;
					(*Q).first = baru;
				}else{
					baru->next = prev->next;
					prev->next = baru;
				}
				baru = NULL;	
			}	
		prev=elmt;
		elmt=elmt->next;
		i+=1;
		}
		
	}else{//jika kosong langsung saja tambahkan
		add(nama, Q);
	}
}
Beispiel #3
0
/*menghapuskan elemen pertama*/
void delFirst(list *L){
	if((*L).first != NULL){
		/*jika list bukan list kosong*/
		elemen *hapus= (*L).first;
		if(countElement(*L) == 1){
			(*L).first = NULL;
		}else{
			(*L).first = (*L).first->next;
			hapus->next = NULL;
		}
		free(hapus);
	}
}
Beispiel #4
0
void del(queue *Q){
	if((*Q).first != NULL){
		/*jika queue tidak kosong*/
		elemen *elmt= (*Q).first;
		if(countElement(*Q) == 1){
			(*Q).first = NULL;
			(*Q).last = NULL;	
		}else{
			(*Q).first = (*Q).first->next;
			elmt->next = NULL;
		}
		free(elmt);
	}
}
Beispiel #5
0
void addAllJlr(queue *Q, graph *G){
	if (countElement(*Q)!=0){
		elemen *elmt = (*Q).first;
		while(elmt!=NULL){
			simpul *awal, *tujuan;
			awal=findSimpul(elmt->elmt.A, *G);
			tujuan=findSimpul(elmt->elmt.B, *G);
			if (awal!=NULL && tujuan!=NULL){
				addJalur(tujuan, elmt->elmt.jarak, awal);
			}
			del(Q);
			elmt = (*Q).first;
		}
	}
}
Beispiel #6
0
/*menghapus elemen terakhir*/
void delLast(list *L){
	if((*L).first != NULL){
		/*jika list tidak kosong*/
		if(countElement(*L) == 1){
			/*list terdiri dari satu elemen*/
			delFirst(L);
		}else{
			/*mencari elemen terakhir list*/
			elemen *last = (*L).first;
			elemen *prev;
			while(last->next != NULL){
				/*iterasi*/
				prev= last;
				last = last->next;
			}
			delAfter(prev, L);
		}
	}
}
Beispiel #7
0
/***
	This function builds the list of clauses wich belong to IF node
*/
void buildClauses(xmlNode *node, tclauses_cond *clauses){

	int qtclauses, i;
	xmlNode *current, *probability;
	char *tmp;

	qtclauses = countElement(node, "condition");
	if (qtclauses > 0){
		clauses->lconditions = (tcondition *) malloc(sizeof(tcondition) * qtclauses);
		clauses->qtclauses = qtclauses;
		current = node->children;
		i=0;
		while(current) // scan tags condition
		{
			if (!strcmp((char *)current->name, "condition")){ // "probability"
				clauses->lconditions[i].timesexec = 0;
				tmp = getAttrStr(current, "id");
				strncpy(clauses->lconditions[i].info_cond.id, tmp, 5);
				free(tmp);
				clauses->lconditions[i].info_cond.clock_cycles = getAttrDbl(current, "clock-cycles");
				clauses->lconditions[i].info_cond.energy = getAttrDbl(current, "energy");
				clauses->lconditions[i].info_cond.consumed_cycles = 0.0;
				clauses->lconditions[i].info_cond.consumed_energy = 0.0;
				probability = current->children;
				while(probability) // scan tags probability
				{
					if (!strcmp((char *)probability->name, "probability")){
						start_range = getAttrDbl(probability, "start-range");
						end_range = getAttrDbl(probability, "end-range");
						step = getAttrDbl(probability, "step");
						clauses->lconditions[i].probability.prob_start = getAttrDbl(probability, "start");
						clauses->lconditions[i].probability.prob_finish = getAttrDbl(probability, "finish");
						clauses->lconditions[i].probability.probability_density_function = getAttrChr(probability, "pdf");
					}
					probability = probability->next;
				}
				i++;
			}
			current = current->next;
		}
	}
}