コード例 #1
0
ファイル: complement.c プロジェクト: cryptica/mist
/* 
 * As assumption we know that the IST passed in argument is determinized 
 */
static ISTHeadListNode* complete_list_of_sons(ISTNode *Node){

	ISTSon *son;
	ISTNode *new_node;
	ISTHeadListNode *list_node; 
	long current_value;

	son = Node->FirstSon;
	ist_init_list_node(&list_node);
	if (son == NULL) {
		new_node = ist_create_node(ist_build_interval(0L,INFINITY));
		ist_insert_list_node(list_node,new_node) ;
	} else {
		current_value = 0;

		while (son != NULL && current_value != INFINITY ) {
			if (son->Son->Info->Left > current_value){
				new_node = ist_create_node(ist_build_interval(current_value,son->Son->Info->Left-1));
				ist_insert_list_node(list_node,new_node) ;
			}
			current_value = (son->Son->Info->Right == INFINITY ) ? INFINITY : son->Son->Info->Right+1;
			son = son->Next;
		}
		if (current_value != INFINITY ) {
			new_node = ist_create_node(ist_build_interval(current_value,INFINITY));
			ist_insert_list_node(list_node,new_node) ;
		}

	}
	return list_node;
}
コード例 #2
0
ファイル: codegengoals.c プロジェクト: pevalme/mist
static
void
goals(T_PTR_tree entry, ISTSharingTree *unsafe) {
	size_t i;
	char* info;

	if (entry) {
		info = (char*) tree_getinfo(entry);
		if (strcmp(info,"or") == 0) {
			tokensgoals = (ISTInterval**)xmalloc(nbr_var*tree_nbrsubtrees(entry)*sizeof(ISTInterval *));
			for (i = 0 ; i < nbr_var * tree_nbrsubtrees(entry) ; i++)
				tokensgoals[i] = ist_build_interval(0,INFINITY);

			for (nbrgoalscmd = 0 ; nbrgoalscmd < tree_nbrsubtrees(entry) ; nbrgoalscmd++)
				goalsor(tree_subtree(entry,nbrgoalscmd));

		} else if (strcmp(info,"and") == 0) {
			nbrgoalscmd = 0;

			tokensgoals = (ISTInterval **)xmalloc(nbr_var * sizeof(ISTInterval *));
			for (i = 0 ; i < nbr_var; i++)
				tokensgoals[i] = ist_build_interval(0,INFINITY);

			goalsor(entry);

			nbrgoalscmd = 1;
		}
		for (i = 0; i < nbrgoalscmd; ++i) {
			if (ist_add(unsafe, &tokensgoals[i * nbr_var], nbr_var) == false)
				err_msg("codegengoals.c: redundant unsafe cones\n");
		}
		for (i=0;i<nbr_var*nbrgoalscmd;++i)
			xfree(tokensgoals[i]);
		xfree(tokensgoals);
	}
}
コード例 #3
0
ファイル: codegeninit.c プロジェクト: pevalme/mist
static
void
init(T_PTR_tree entry, ISTSharingTree *initial) {
  size_t i;
  char* info;

  if (entry) {
    info = (char*) tree_getinfo(entry);
    if (strcmp(info,"and") == 0) {
      nbrinitcmd = 0;

      tokensinit = (ISTInterval **)xmalloc(nbr_var*sizeof(ISTInterval *));
      for (i = 0 ; i < nbr_var; i++)
		  tokensinit[i] = ist_build_interval(0,INFINITY);

      initor(entry);
      nbrinitcmd = 1;
	  ist_add(initial,tokensinit, nbr_var);
    }
  }
}
コード例 #4
0
ファイル: complement.c プロジェクト: cryptica/mist
void ist_complement(ISTSharingTree *S, size_t dim)
{
	ISTLayer *Layer;
	ISTNode *Node, *new_node, *rnode;
	ISTHeadListNode *list_node;
    ISTInterval **tuple;
	int i;	

	if (ist_is_empty(S) == false) {
		/*First step: determinisation */	
		ist_determinize(S);
		/* Special case where we have only one variable */
		if(dim<=1) {
			/*complementation in itself */
			list_node = complete_list_of_sons(S->Root);
			new_node = ist_remove_first_elem_list_node(list_node);
			ist_remove_sons(S->Root);
			ist_remove_node_without_father_layer(S->FirstLayer);
			while (new_node != NULL){
				/*
				 * Caution, ist_add_node don't necesseraly return new_node ... 
				 * e.g. imagine one node without son in layer and you want insert a same node without sons
				 */
				rnode=ist_add_node(S->FirstLayer,new_node);
				ist_add_son(S->Root,rnode);
				ist_add_son(rnode,S->LastLayer->FirstNode);
				new_node = ist_remove_first_elem_list_node(list_node);
			}
			xfree(list_node);

		} else {

			/*complementation in itself */
			list_node = complete_list_of_sons(S->Root);
			new_node = ist_remove_first_elem_list_node(list_node);
			while (new_node != NULL){
				/*
				 * Caution, ist_add_node don't necesseraly return new_node ... 
				 * e.g. imagine one node without son in layer and you want insert a same node without sons
				 */
				ist_add_son(S->Root,ist_add_node(S->FirstLayer,new_node));
				new_node = ist_remove_first_elem_list_node(list_node);
			}
			xfree(list_node);

			/* Now the general case */
			Layer = S->FirstLayer;
			while (Layer != S->LastLayer->Previous){
				/* We have at least two variables in the system ! */
				Node = Layer->FirstNode;
				while (Node != NULL){
					list_node = complete_list_of_sons(Node);
					if (Layer->Next == S->LastLayer->Previous) {
						ist_remove_sons(Node);
						ist_remove_node_without_father_layer(Layer->Next);
					}
					new_node = ist_remove_first_elem_list_node(list_node);
					while (new_node != NULL){
						ist_add_son(Node,ist_add_node(Layer->Next,new_node));
						new_node = ist_remove_first_elem_list_node(list_node);
					}
					xfree(list_node);
					Node = Node->Next;
				}
				Layer = Layer->Next;
			}
			Node = Layer->FirstNode;
			while (Node != NULL) {
				ist_add_son(Node,S->LastLayer->FirstNode);
				Node = Node->Next;
			}
			ist_remove_node_without_son(S);
			/* Special case when true is given in input */
			if (S->Root->FirstSon == NULL) {
				while (S->LastLayer != NULL) {
					ist_remove_last_layer(S);
				}
			} else 
				/* if you ist_remove_sons and that after your list_node is empty, this is the case */
				ist_adjust_second_condition(S);
		}
	} else {
		/* complement of the empty sef of dimension dim*/

		/*First: construction of a tuple corresponding to N^{dim} */
		tuple = (ISTInterval **) xmalloc(dim * sizeof(ISTInterval *));
		for(i = 0;i < dim; i++) 
			tuple[i] = ist_build_interval(0,INFINITY);

		/*adding tuple to S (which is empty) gives us an IST that contains any tuple over positive 
		 * integer of dimension dim*/
		
		ist_add(S,tuple,dim);

		/*free of the tuple */
		for(i = 0; i < dim; i++) {
			ist_dispose_info(tuple[i]);
		}
		xfree(tuple);
	}
}