/** * \brief Plays a random play starting in the initial state according to the strategy of player. * If player wins, returns true, else returns false. */ bool random_strategy_play(const parity_game* g, const recursive_result* strategy, const int player) { treedbs_t tree = TreeDBScreate(g->state_length); int initial_state = TreeFold(tree, g->src); int priority = get_priority(g, g->src); int src[g->state_length]; int dst[g->state_length]; // start from the initial state of g int s = initial_state; int t = s; int l = 0; // how many moves have been played dfs_stack_t states = dfs_stack_create(1); dfs_stack_t priorities = dfs_stack_create(1); dfs_stack_push(states, (int[]){s});
static void write_init(lts_file_t file,int seg,void* state){ uint32_t state_no; switch(lts_file_init_mode(file)){ case Index: state_no=*((uint32_t*)state) * file->segments + seg; break; case SegVector: case Vector: if (seg != 0) Abort("(Seg)Vector format with multiple segments unsupported"); state_no=TreeFold(file->lts->state_db,state); break; default: Abort("missing case"); } if (file->init_count>=file->lts->root_count) { lts_set_size(file->lts,file->lts->root_count+32,file->lts->states,file->lts->transitions); } file->lts->root_list[file->init_count]=state_no; file->init_count++; }
static void lts_lump(lts_t lts){ int found; uint32_t i, k, j, count, oldbegin; lts_set_type(lts,LTS_BLOCK); count=0; uint32_t rate[2]; uint32_t temp[2]; for(i=0;i<lts->states;i++){ oldbegin=lts->begin[i]; lts->begin[i]=count; for(j=oldbegin;j<lts->begin[i+1];j++){ found=0; for(k=lts->begin[i];k<count;k++){ if(lts->dest[j]==lts->dest[k]){ TreeUnfold(lts->edge_idx,lts->label[k],(int*)rate); TreeUnfold(lts->edge_idx,lts->label[j],(int*)temp); uint64_t teller=((uint64_t)rate[0])*((uint64_t)temp[1]); teller+=((uint64_t)temp[0])*((uint64_t)rate[1]); uint64_t noemer=((uint64_t)rate[1])*((uint64_t)temp[1]); uint64_t gcd=gcd64(teller,noemer); rate[0]=teller/gcd; rate[1]=noemer/gcd; lts->label[k]=TreeFold(lts->edge_idx,(int*)rate); found=1; break; } } if (!found){ lts->label[count]=lts->label[j]; lts->dest[count]=lts->dest[j]; count++; } } } lts->begin[lts->states]=count; lts_set_size(lts,lts->root_count,lts->states,count); }
int main(int argc, char *argv[]){ char* files[2]; HREinitBegin(argv[0]); HREaddOptions(options,"Tool for transforming labeled transition systems\n\nOptions"); lts_lib_setup(); HREinitStart(&argc,&argv,1,2,files,"<input> [<output>]"); int me=HREme(HREglobal()); int peers=HREpeers(HREglobal()); if (peers>1) Abort("parallelizing this tool is future work");(void)me; string_set_t label_set=NULL; if (label_filter!=NULL){ label_set=SSMcreateSWPset(label_filter); } switch(task){ case Undefined: Abort("task unspecified"); case LTScopy: if (files[1]==NULL) Abort("second argument required for copy."); Print(infoShort,"streaming copy from %s to %s",files[0],files[1]); lts_file_t in=lts_file_open(files[0]); lts_type_t ltstype=lts_file_get_type(in); rd_seg=lts_file_get_segments(in); if (wr_seg==0) { wr_seg=rd_seg; } else { Abort("on-the-fly changing the number of segments is future work"); } lts_file_t out; if (label_set==NULL){ out=lts_file_create(files[1],ltstype,wr_seg,in); } else { out=lts_file_create_filter(files[1],ltstype,label_set,wr_seg,in); } int N=lts_type_get_type_count(ltstype); for(int i=0;i<N;i++){ char*name=lts_type_get_type(ltstype,i); switch(lts_type_get_format(ltstype,i)){ case LTStypeDirect: case LTStypeRange: Debug("integer type %s does not use tables",name); break; case LTStypeChunk: case LTStypeEnum: Debug("creating table for type %s",name); value_table_t tmp=chunk_table_create(NULL,name); Debug("set in %s",name); lts_file_set_table(in,i,tmp); Debug("set out %s",name); lts_file_set_table(out,i,tmp); break; } } lts_file_copy(in,out); lts_file_close(out); lts_file_close(in); break; case LTSrdwr: if (files[1]==NULL) Abort("second argument required for rdwr."); Print(infoShort,"loading from %s",files[0]); lts_t lts=lts_create(); lts_read(files[0],lts); if (encode) { Print(infoShort,"single edge label encoding"); lts=lts_encode_edge(lts); } if (bfs_reorder) { Print(infoShort,"reindexing LTS in BFS order"); lts_bfs_reorder(lts); } Print(infoShort,"storing in %s",files[1]); if(wr_seg==0) wr_seg=1; lts_write(files[1],lts,label_set,wr_seg); break; case LTSindex:{ if (peers>1) Abort("parallelizing this tool is future work"); if (files[1]==NULL) Abort("second argument required for index."); Print(infoShort,"opening %s",files[0]); lts_file_t in=lts_file_open(files[0]); lts_type_t ltstype=lts_file_get_type(in); int segments=lts_file_get_segments(in); lts_file_t settings=lts_get_template(in); if (lts_file_get_edge_owner(settings)!=SourceOwned) Abort("bad edge owner"); lts_file_set_dest_mode(settings,Index); lts_file_set_init_mode(settings,Index); Print(infoShort,"creating %s",files[1]); lts_file_t out=lts_file_create(files[1],ltstype,segments,settings); int N=lts_type_get_type_count(ltstype); for(int i=0;i<N;i++){ char*name=lts_type_get_type(ltstype,i); switch(lts_type_get_format(ltstype,i)){ case LTStypeDirect: case LTStypeRange: Debug("integer type %s does not use tables",name); break; case LTStypeChunk: case LTStypeEnum: Debug("creating table for type %s",name); value_table_t tmp=chunk_table_create(NULL,name); Debug("set in %s",name); lts_file_set_table(in,i,tmp); Debug("set out %s",name); lts_file_set_table(out,i,tmp); break; } } treedbs_t db[segments]; int SV=lts_type_get_state_length(ltstype); int SL=lts_type_get_state_label_count(ltstype); int K=lts_type_get_edge_label_count(ltstype); for(int i=0;i<segments;i++){ Print(info,"loading and copying states of segment %d",i); uint32_t state[SV]; uint32_t label[SL]; db[i]=TreeDBScreate(SV); int idx=0; while(lts_read_state(in,&i,state,label)){ int tmp=TreeFold(db[i],(int*)state); if (idx!=tmp){ Abort("unexpected index %u != %u",tmp,idx); } idx++; lts_write_state(out,i,(int*)state,label); } } Print(info,"converting initial states"); { uint32_t seg; uint32_t state[SV]; while(lts_read_init(in,(int*)&seg,state)){ int idx=TreeFold(db[seg],(int*)state); lts_write_init(out,seg,&idx); } } for(int i=0;i<segments;i++){ Print(info,"converting edges of segment %d",i); uint32_t src_state[1]; uint32_t dst_seg; uint32_t dst_state[SV]; uint32_t label[K]; while(lts_read_edge(in,&i,src_state,(int*)&dst_seg,dst_state,label)){ int idx=TreeFold(db[dst_seg],(int*)dst_state); lts_write_edge(out,i,src_state,dst_seg,&idx,label); } } lts_file_close(out); lts_file_close(in); } } Print(infoShort,"done"); HREexit(LTSMIN_EXIT_SUCCESS); }
int main(int argc, char *argv[]){ char *files[2]; RTinitPopt(&argc,&argv,options,1,2,files,NULL,"<model> [<lts>]", "Perform an enumerative reachability analysis of <model>\n" "Run the TorX remote procedure call protocol on <model> (--torx).\n\n" "Options"); if (files[1]) { Warning(info,"Writing output to %s",files[1]); write_lts=1; } else { Warning(info,"No output, just counting the number of states"); write_lts=0; } if (application==RunTorX && write_lts) Fatal(1,error,"A TorX server does not write to a file"); Warning(info,"loading model from %s",files[0]); model_t model=GBcreateBase(); GBsetChunkMethods(model,new_string_index,NULL, (int2chunk_t)SIgetC,(chunk2int_t)SIputC,(get_count_t)SIgetCount); GBloadFile(model,files[0],&model); if (RTverbosity >=2) { fprintf(stderr,"Dependency Matrix:\n"); GBprintDependencyMatrix(stderr,model); } if (matrix) { GBprintDependencyMatrix(stdout,model); exit(0); } lts_type_t ltstype=GBgetLTStype(model); N=lts_type_get_state_length(ltstype); edge_info_t e_info=GBgetEdgeInfo(model); K=e_info->groups; Warning(info,"length is %d, there are %d groups",N,K); state_labels=lts_type_get_state_label_count(ltstype); edge_labels=lts_type_get_edge_label_count(ltstype); Warning(info,"There are %d state labels and %d edge labels",state_labels,edge_labels); if (state_labels&&write_lts&&!write_state) { Fatal(1,error,"Writing state labels, but not state vectors unsupported. " "Writing of state vector is enabled with the option --write-state"); } int src[N]; GBgetInitialState(model,src); Warning(info,"got initial state"); int level=0; switch(application){ case ReachVset: domain=vdom_create_default(N); visited_set=vset_create(domain,0,NULL); next_set=vset_create(domain,0,NULL); if (write_lts){ output=lts_output_open(files[1],model,1,0,1,"viv",NULL); lts_output_set_root_vec(output,(uint32_t*)src); lts_output_set_root_idx(output,0,0); output_handle=lts_output_begin(output,0,0,0); } vset_add(visited_set,src); vset_add(next_set,src); vset_t current_set=vset_create(domain,0,NULL); while (!vset_is_empty(next_set)){ if (RTverbosity >= 1) Warning(info,"level %d has %d states, explored %d states %d trans", level,(visited-explored),explored,trans); level++; vset_copy(current_set,next_set); vset_clear(next_set); vset_enum(current_set,explore_state_vector,model); } long long size; long nodes; vset_count(visited_set,&nodes,&size); Warning(info,"%lld reachable states represented symbolically with %ld nodes",size,nodes); break; case ReachTreeDBS: dbs=TreeDBScreate(N); if(TreeFold(dbs,src)!=0){ Fatal(1,error,"expected 0"); } if (write_lts){ output=lts_output_open(files[1],model,1,0,1,write_state?"vsi":"-ii",NULL); if (write_state) lts_output_set_root_vec(output,(uint32_t*)src); lts_output_set_root_idx(output,0,0); output_handle=lts_output_begin(output,0,0,0); } int limit=visited; while(explored<visited){ if (limit==explored){ if (RTverbosity >= 1) Warning(info,"level %d has %d states, explored %d states %d trans", level,(visited-explored),explored,trans); limit=visited; level++; } TreeUnfold(dbs,explored,src); explore_state_index(model,explored,src); } break; case RunTorX: { torx_struct_t context = { model, ltstype }; torx_ui(&context); return 0; } } if (write_lts){ lts_output_end(output,output_handle); Warning(info,"finishing the writing"); lts_output_close(&output); Warning(info,"state space has %d levels %d states %d transitions",level,visited,trans); } else { printf("state space has %d levels %d states %d transitions\n",level,visited,trans); } return 0; }
int main(int argc, char *argv[]){ char* files[2]; RTinitPopt(&argc,&argv,options,2,2,files,NULL,"<input> <output>","Stream based file format conversion\n\nOptions"); model_t model=GBcreateBase(); GBsetChunkMethods(model,new_string_index,NULL, (int2chunk_t)SIgetC,(chunk2int_t)SIputC,(get_count_t)SIgetCount); Warning(info,"copying %s to %s",files[0],files[1]); lts_input_t input=lts_input_open(files[0],model,0,1); if (segments==0) { segments=lts_input_segments(input); } char*input_mode=lts_input_mode(input); if (input_mode) { Warning(debug,"input was written in %s mode",input_mode); if (!strcmp(input_mode,"viv") || !strcmp(input_mode,"vsi")){ if (segments!=1) Fatal(1,error,"cannot write more than one segment"); lts_type_t ltstype=GBgetLTStype(model); int N=lts_type_get_state_length(ltstype); Warning(info,"state length is %d",N); treedbs_t dbs=TreeDBScreate(N); // we should convert the GB not and not hack the ltstype. lts_type_set_state_label_count(ltstype,0); lts_output_t output=lts_output_open(files[1],model,segments,0,1,"-ii",NULL); lts_output_set_root_idx(output,0,0); lts_enum_cb_t ecb=lts_output_begin(output,segments,segments,segments); // We should have two passes (if the file is not in BFS order then the state numbers are wrong!) // pass 1: states with labels. // pass 2: edges with labels. // Currently the viv reader illegally does two passes. N=lts_input_segments(input); uint32_t begin[N]; lts_count_t *count=lts_input_count(input); begin[0]=0; for(int i=1;i<N;i++) begin[i]=begin[i-1]+count->state[i-1]; struct dbs_ctx ctx; ctx.dbs=dbs; ctx.begin=begin; lts_input_enum(input,N,N,N,lts_enum_convert(ecb,&ctx,dbs_fold,dbs_unfold,1)); lts_output_end(output,ecb); lts_output_close(&output); uint32_t* root=lts_input_root(input); uint32_t root_no=TreeFold(dbs,(int*)root); if (root_no!=0){ Fatal(1,error,"root is %u rather than 0",root_no); } } else { Warning(info,"input mode %s not supported",input_mode); } } else if (segments==lts_input_segments(input)){ Warning(debug,"undefined input mode"); lts_output_t output=lts_output_open(files[1],model,segments,0,1,"-ii",NULL); lts_output_set_root_idx(output,lts_root_segment(input),lts_root_offset(input)); lts_enum_cb_t ecb=lts_output_begin(output,segments,segments,segments); lts_input_enum(input,segments,segments,segments,ecb); lts_output_end(output,ecb); lts_output_close(&output); } else { Warning(debug,"undefined input mode with segment conversion"); int N=lts_input_segments(input); uint64_t offset[N+1]; lts_count_t *count=lts_input_count(input); offset[0]=segments; offset[1]=0; for(int i=1;i<N;i++){ offset[i+1]=offset[i]+count->state[i-1]; } uint64_t root=offset[lts_root_segment(input)+1]+lts_root_offset(input); lts_output_t output=lts_output_open(files[1],model,segments,0,1,"-ii",NULL); lts_output_set_root_idx(output,root%segments,root/segments); lts_enum_cb_t ecb=lts_output_begin(output,segments,segments,segments); lts_input_enum(input,N,N,N,lts_enum_convert(ecb,offset,convert_div_mod,copy_seg_ofs,1)); lts_output_end(output,ecb); lts_output_close(&output); } lts_input_close(&input); return 0; }
static void dbs_fold(void*context,int *vec,int *seg,int *ofs){ struct dbs_ctx *ctx=(struct dbs_ctx *)context; *seg=0; *ofs=TreeFold(ctx->dbs,vec); }