Exemple #1
0
void solve()
{
    initheap();
    greedy();
    update();
    if (Kl > K) cai_tien();
}
/* Load a program into the vm and initialize its state. */
void load(struct _context* ctx, avm* vm, assembly* p )
{
	int i;
	symbol* s;
	if (!p) return;
	vm->ctx = ctx;
	vm->instructions = p->instructions;
	vm->numins = p->nextslot;
	vm->pc = p->entry;
	for (i=0; i<NUM_REGS; i++)
		seti(&vm->regs[i], 0);
	if ((vm->hs=(stack*)calloc(1, sizeof(stack))) == 0)
	{
		setvmerror(vm, ZEN_VM_OUT_OF_MEMORY);
		return;
	}
	vm->hs->size = p->stacksize;
	vm->hs->sbody = (word*)calloc(vm->hs->size, sizeof(word));
	vm->hs->fp = vm->hs->sp = 0;
	vm->cs = vm->hs;
	vm->lasterror = ZEN_NO_ERROR;
	initheap(vm, &vm->hp);
	s = lookupall(0, ctx, GLOBAL_NAME);
	vm->globalsize = s->localsize+s->tempsize;
	vm->regs[rs].entity.ival += vm->globalsize;
	vm->tot.size = ZEN_INITIALTOTSIZE;
	if (!(vm->tot.table = calloc(vm->tot.size, sizeof(pair))))
	{
		setvmerror(vm, ZEN_VM_OUT_OF_MEMORY);
		return;
	}
	vm->loaded = 1;
}
Exemple #3
0
// Read code from file and execute it
int main(int argc, char** argv) {
  if (sizeof(word)!=4 || sizeof(word*)!=4 || sizeof(int)!=4) {
    printf("Size of word, word* or int is not 32 bit, cannot run\n");
    return -1;
  } else if (argc < 2) {
    printf("Usage: listmachine [-trace] <programfile> <arg1> ...\n");
    return -1;
  } else {
    int trace = argc >= 3 && 0==strncmp(argv[1], "-trace", 7);
    initheap();
    return execute(argc, argv, trace);
  }
}
Exemple #4
0
void dijkstra(int s)
{
	memset(dis,0x77,sizeof(dis));
	dis[s]=0;
	initheap();
	for(int i=1;i<=n;++i) insert(dis[i],i);
	while(size)
	{
		int th=h[1],tid=id[1];
		extmin();
		dis[tid]=th;
		for(Edge *tmp=edge[tid];tmp!=NULL;tmp=tmp->next)
			change(loc[tmp->v],th+tmp->w);
	}
}
Exemple #5
0
int astar()
{
//	printf("%d\n",1);

	initheap();
	insert(dis[S],S);
	while(size)
	{
	//	printf("%d\n",size);
		int th=h[1],tid=id[1];
		extmin();
		
		++c[tid];
		if(c[T]==K) return th;
		if(c[tid]>K) continue;
		for(Edge *tmp=edge[tid];tmp!=NULL;tmp=tmp->next)
			insert(th-dis[tid]+dis[tmp->v]+tmp->w,tmp->v);
	}
	return -1;
}