示例#1
0
void
Client::StartWorker(workMode pMode) {
    int msgsize = 1 + (int) (250000.0 * (rand() / (RAND_MAX + 1.0)));
    char* buf = CreateBuffer(&msgsize);

    //fill data part of buffer with random bytes
    for (int i = 2; i < (msgsize); i++) {
        buf[i] = i % 256;
    }

    if (pMode == THREADS) {
        ThreadWorker* c = new ThreadWorker(m_host,buf,msgsize+2);
        if (c->Create() != wxTHREAD_NO_ERROR) {
            wxLogError(wxT("Cannot create more threads"));
        } else {
            c->Run();
            m_threadWorkers.Append(c);
        }
    } else {
        EventWorker* e = new EventWorker(m_host,buf,msgsize+2);
        e->Run();
        m_eventWorkers.Append(e);
    }
    m_statConnecting++;
}
示例#2
0
void TAstar::Search()
{
	TAstar T = *this;              //初始结点   
	T.f = T.Calcuf();               //初始结点的估价函数   
	TList<TAstar> L;           //建立队列   
	L.Append(T);                 //初始结点入队   
	int head = 0, tail = 0;           //队列头和尾指针   
	while (head <= tail)           //队列不空则循环   
	{
		for (int i = 0; i<4; i++)            //空格可能移动方向   
		{
			T = L.GetData(head);   //去队列头结点   
			if (T.h == 0)                   //是目标结点   
			{
				T.Printl(L);//输出搜索路径   
				//T.Printf();    //输出目标状态   
				//printf("%d\n", T.getZeroPos());
				this->rs.push_back(T.getZeroPos());
				return;        //结束   
			}
			if (T.Expend(i))          //若结点可扩展   
			{
				int k = T.Repeat(L); //返回与已扩展结点重复的序号        
				if (k<head)               //如果是不能扩展的结点   
					continue; //丢弃   
				T.last = head;      //不是不能扩展的结点,记录父结点   
				T.f = T.Calcuf(); //计算f   
				if (k <= tail)         //新结点与可扩展结点重复   
				{
					TAstar Temp = L.GetData(k);
					if (Temp.g>T.g)         //比较两结点g值   
						L.SetData(T, k); //保留g值小的   
					continue;
				}
				T.Sort(L, head);            //新结点插入可扩展结点队列        
				tail++;        //队列尾指针后移    
			}
		}
		head++; //一个结点不能再扩展,队列头指针指向下一结点   
	}
}
示例#3
0
void
Client::StartWorker(workMode pMode, const wxString& pMessage) {
    char* tmpbuf = wxStrdup(pMessage.mb_str());
    int msgsize = strlen(tmpbuf);
    char* buf = CreateBuffer(&msgsize);
    memset(buf+2,0x0,msgsize);
    memcpy(buf+2,tmpbuf,msgsize);
    free(tmpbuf);

    if (pMode == THREADS) {
        ThreadWorker* c = new ThreadWorker(m_host,buf,msgsize+2);
        if (c->Create() != wxTHREAD_NO_ERROR) {
            wxLogError(wxT("Cannot create more threads"));
        } else {
            c->Run();
            m_threadWorkers.Append(c);
        }
    } else {
        EventWorker* e = new EventWorker(m_host,buf,msgsize+2);
        e->Run();
        m_eventWorkers.Append(e);
    }
    m_statConnecting++;
}