Пример #1
0
int main() {
    GridWorld world;

    // This is optional, and should make solving the model almost instantaneous.
    // Unfortunately, since our main model is so big, the copying process
    // still takes a lot of time. But at least that would be a one-time cost!
    std::cout << currentTimeString() << "- Copying model...!\n";
    AIToolbox::MDP::SparseModel model(world);
    std::cout << currentTimeString() << "- Init solver...!\n";

    // This is a method that solves MDPs completely. It has a couple of
    // parameters available.
    // The only non-optional parameter is the horizon of the solution; as in
    // how many steps should the solution look ahead in order to decide which
    // move to take. If we chose 1, for example, the tiger would only consider
    // cells next to it to decide where to move; this wouldn't probably be
    // what we want.
    // We want the tiger to think for infinite steps: this can be
    // approximated with a very high horizon, since in theory the final solution
    // will converge to a single policy anyway. Thus we put a very high number
    // as the horizon here.
    AIToolbox::MDP::ValueIteration<decltype(model)> solver(1000000);

    std::cout << currentTimeString() << "- Starting solver!\n";
    // This is where the magic happen. This could take around 10-20 minutes,
    // depending on your machine (most of the time is spent on this tutorial's
    // code, however, since it is a pretty inefficient implementation).
    // But you can play with it and make it better!
    //
    // If you are using the Sparse Model though, it is instantaneous since
    // Eigen is very very efficient in computing the values we need!
    auto solution = solver(model);

    std::cout << currentTimeString() << "- Problem solved? " << std::get<0>(solution) << "\n";

    AIToolbox::MDP::Policy policy(world.getS(), world.getA(), std::get<1>(solution));

    std::cout << "Printing best actions when prey is in (5,5):\n\n";
    for ( int y = 10; y >= 0; --y ) {
        for ( int x = 0; x < 11; ++x ) {
            std::cout << policy.sampleAction( encodeState(CoordType{{x, y, 5, 5}}) ) << " ";
        }
        std::cout << "\n";
    }

    std::cout << "\nSaving policy to file for later usage...\n";
    {
        // You can load up this policy again using ifstreams.
        // You will not need to solve the model again ever, and you
        // can embed the policy into any application you want!
        std::ofstream output("policy.txt");
        output << policy;
    }

    return 0;
}
int main(int argc, char** argv) {
    startTimeString = currentTimeString();

    if (argc < 2) {
        printf("Usage: %s SCENEFILE.txt\n", argv[0]);
        return 1;
    }

    const char *sceneFile = argv[1];

    // Load scene file
    scene = new Scene(sceneFile);//marerial, object, camera

    // Set up camera stuff from loaded path tracer settings
    iteration = 0;
    renderState = &scene->state;
    width = renderState->camera.resolution.x;
    height = renderState->camera.resolution.y;

    // Initialize CUDA and GL components
    init();

    // GLFW main loop
    mainLoop();//runCUDA
//	getchar();
    return 0;
}
Пример #3
0
void chat_client_pressedReturnKey(void *t, const char *msg) {
        TForm1 *tform1 = (TForm1 *) t;
        if (ircThreadInstance && ircThreadInstance->sd) {
                sendMessage(msg);
                appendText(tform1,  currentTimeString( ) +  " - " + playerName + ": " + msg);
        }
}
Пример #4
0
void  getplayername() {
        String currentOFPPlayer = WINDOW_SETTINGS->getCurrentPlayerName();
        if(currentOFPPlayer.IsEmpty()) {
                string tmp = "Guest" + currentTimeString();
                strcpy(playerName, tmp.c_str());
        } else {
                strcpy(playerName, currentOFPPlayer.c_str());
        }
        return;
}
Пример #5
0
DWORD WINAPI irc_ThreadProc_ReconnectWatchThread (LPVOID lpdwThreadParam__ ) {
       while(true) {
            Sleep(300 * 1000); // sleep longer time until nickname in use is solved
            if (ircThreadInstance && ircThreadInstance->sd) {
                int r = ircThreadInstance->sendString("PING " + ircThreadInstance->hoscht);
                if (r < 0) {
                    // could not set send, trying to reconnect
                    
                        ircThreadInstance->userz.clear();
                        ircThreadInstance->playersParted.clear();
                        ircThreadInstance->playersJoined.clear();
                        ircThreadInstance->userzSorted.clear();
                        ircThreadInstance->updatePlayers = 1;
                        ircThreadInstance->messages.push_back(  currentTimeString( ) +  " - trying to reconnect"  );
                        chat_client_connect();
                }
            }
       }
}
Пример #6
0
/***********************************************************************
 *  Method: MonteCarloAnalysis::updateImpl
 *  Params: 
 * Returns: void
 * Effects: 
 ***********************************************************************/
void
MonteCarloAnalysis::updateImpl()
{
	const Forest* f = ((ForestAnalysis*)inputs[0])->getForest();
	nodeCount = f->getGraph().size();
	std::cout << currentTimeString() << " Forest has " << nodeCount << " nodes" << std::endl;
	vecN pf = ((AxesAnalysis*)inputs[1])->getPF();
	WidthCalculator wco(f, pf);
	originalWidth = wco.getWidth();
	DistributionAnalysis* dist = (DistributionAnalysis*)inputs[2];
	widths.clear();
	int nodeCount = f->getGraph().size();
	for (int i = 0; i < mTreeCount; i++)
	{
		if (!(i % 20)) std::cout << i / 10;
		else if (!(i % 10)) std::cout << ".";
		auto angleGenerator = std::bind(&DistributionAnalysis::generateAngle, dist,std::placeholders::_1,std::placeholders::_2);
		int alteredNodeCount;
		Forest* ff = f->generateForest(angleGenerator, pf, alteredNodeCount);
		WidthCalculator wc(ff, pf);
		widths.push_back(wc.getWidth());
		alteredFractions.push_back(((float)alteredNodeCount) / nodeCount);
		assert(f->compare(ff));
		delete ff;
	}
	std::cout << std::endl;
	mean = { 0.f, 0.f, 0.f };
	for (const auto width : widths)
	{
		mean = mean + width;
	}
	mean = mean / mTreeCount;
	SD = { 0.f, 0.f, 0.f };
	for (const auto width : widths)
	{
		SD = SD + (width - mean)*(width - mean);
	}
	SD = SD / mTreeCount; // mTreeCount-1?
	SD = SD.sqrtWG();
	discrepancy = (mean - originalWidth) / SD;

}
Пример #7
0
void chat_client_timercallback(void * t) {
        TForm1 *tform1 = (TForm1 *) t;

        if (ircThreadInstance && ircThreadInstance->messages.size() > 0) {
                vector<string> m  (ircThreadInstance->messages);
                ircThreadInstance->messages.clear();
                //string privMsgNeedle = "PRIVMSG #" + channelname_operationflashpoint1 + " :";
                string privMsgNeedle = Form1->getChatChannel().c_str();
                privMsgNeedle = "PRIVMSG #" + privMsgNeedle + " :";
                for(int i = 0; i < m.size(); i++) {
                        string& omsg = m.at(i);
                        if (INPUTOUT) {
                                appendText(tform1, omsg);
                        }
                        string cmsg = omsg;
                        string playername;
                        int fnd = 0;
                        if ((fnd = cmsg.find(privMsgNeedle,0)) >= 0) {
                                cmsg = string(cmsg, fnd + privMsgNeedle.size());
                                int emp = omsg.find("!", 1);
                                playername = string(omsg, 1, emp - 1);
                                playername = name_irctolocal(playername);
				if(!Form1->isChatUserBlocked(playername.c_str())) {                                
					cmsg = currentTimeString() + " - " + playername + ": " + cmsg;
                                	appendText(tform1, cmsg);
                                        if(Form1->doNameFilter(cmsg.c_str(), playerName) ||
                                           Form1->doNameFilter(cmsg.c_str(), (ofpprefix + plrname_localtoirc(playerName)).c_str())) {
                                               tform1->ChatNotification(cmsg.c_str());
                                        }
				}
                        }
                }
        }

        if (0 && ircThreadInstance && ircThreadInstance->userz.size() > 0) {
                vector<string> m  (ircThreadInstance->userz);
                ircThreadInstance->userz.clear();
                for(int i = 0; i < m.size(); i++) {
                        TStringGrid *tssg = tform1->StringGrid3;
                        int rc =  tssg->RowCount;
                        tssg->RowCount = rc + 1;
                        string& stre = m.at(i);
                        string convertedPlayerName = name_irctolocal( stre );
                        tssg->Cells[0][rc] = convertedPlayerName.c_str();
                }
        }

        if (ircThreadInstance->updatePlayers) {
                ircThreadInstance->updatePlayers = 0;
                set<string> userzSortedCopy = set<string>(ircThreadInstance->userzSorted);
                TStringGrid *tssg = tform1->StringGrid3;
                tssg->RowCount = userzSortedCopy.size();

                // convert to vector
                vector<string> ulist(userzSortedCopy.begin(), userzSortedCopy.end());
                for(int i = 0; i < ulist.size(); i++) {
                        tssg->Cells[0][i] = ulist[i].c_str();
                }
        }

        if (ircThreadInstance->playersParted.size() > 0) {
                vector<string> pp =  vector<string>(ircThreadInstance->playersParted);
                ircThreadInstance->playersParted.clear();
                for(int i = 0; i < pp.size(); i++) {
                        //ircThreadInstance->sendString
                        string text = currentTimeString() + "      *******    "  + pp.at(i) + " ";
                        text += WINDOW_SETTINGS->getGuiString("STRING_CHAT_LEFT").c_str();
                        text += "    ******";
                        appendText(tform1, text);
                }
        }
        if (ircThreadInstance->playersJoined.size() > 0) {
                vector<string> pp =  vector<string>(ircThreadInstance->playersJoined);
                ircThreadInstance->playersJoined.clear();
                for(int i = 0; i < pp.size(); i++) {
                        //ircThreadInstance->sendString
                        string text = currentTimeString() + "      *******    "  + pp.at(i) + " ";
                        text += WINDOW_SETTINGS->getGuiString("STRING_CHAT_JOINED").c_str();
                        text += "    ******";
                        appendText(tform1, text);
                }
        }
}