Labels found useful for Native C++ Development


Using labels in modern programming is often considered a bad practice, as it results in spaghetti (unmaintainable) code. However, I often find it very useful for native C/C++ programming, where no exceptions are used (error handling using return values is extensively used) and memory management is needed.It increases the readability and maintainability of the code to a great extent.

The following code does not utilize a label, it has :

1- A lot of Nested If Loops, causing bad readability.

2- Redundant memory cleaning code, causing bad maintainability.

DWORD Foo_NoLabel() {

DWORD    dwErr = NO_ERROR;
Boo      *pBoo = NULL;
Soo      *pSoo= NULL;
Doo      *pDoo= NULL;
Loo      *pLoo= NULL;

dwErr = GetBoo(&pBoo);
if (dwErr == NO_ERROR)  {
    dwErr = GetSoo(&pSoo);
    if (dwErr == NO_ERROR) {
        dwErr = GetDoo(&pDoo);
        if (dwErr == NO_ERROR) {
            dwErr = GetLoo(&pLoo);
            if (dwErr == NO_ERROR) {
                //Great!
            }
            else {
                //Oops!
                delete pBoo;
                delete pSoo;
                delete pDoo;
            }
        }
        else {
            //Oops!
            delete pBoo;
            delete pSoo;
        }
     }
    else {
        //Oops!
        delete pBoo;
     }
}

if (dwErr == NO_ERROR) {
    dwErr = UseAll(pBoo,pLoo,pDoo,pSoo);

    delete pBoo;
    delete pSoo;
    delete pDoo;
    delete pLoo;
}

return dwErr;

}

This much cleaner code uses a CleanUp label:


DWORD Foo_UsingLabel() {

DWORD    dwErr = NO_ERROR;
Boo      *pBoo = NULL;
Soo      *pSoo= NULL;
Doo      *pDoo= NULL;
Loo      *pLoo= NULL;

dwErr = GetBoo(&pBoo);
if (dwErr != NO_ERROR)  { goto CleanUp;}

dwErr = GetSoo(&pSoo);
if (dwErr != NO_ERROR)  { goto CleanUp;}

dwErr = GetDoo(&pDoo);
if (dwErr != NO_ERROR)  { goto CleanUp;}

dwErr = GetLoo(&pLoo);
if (dwErr != NO_ERROR)  { goto CleanUp;}

dwErr = UseAll(pBoo,pLoo,pDoo,pSoo);

CleanUp:
if (pBoo) delete pBoo;
if (pSoo) delete pSoo;
if (pDoo) delete pDoo;
if (pLoo) delete pLoo;

return dwErr;
}

 

Representing a state in a compact way


Many algorithms depend on representing the states of many objects in the domain world in the smallest way ever.

This is some C++ code to do this:

int GetWorldState(vector<Obj> *Objs)
{
int state = 0;

for(int i = 0 ; i <Objs->size(); i++)
{
//Shift the next bit to be initialized
state <<= 1;

//Get the current object
Obj * ch = &Objs->operator [](i);

//Fill the bit if object has a special property, otherwise don't
if ( Obj->isLeft ) state |= 1;
}

//Return the final result
return state;
}

This idea can be generalized to include complex objects.

Software Engineering and AI: The Gigantic Picture


Introduction

AI research aims to devise techniques to make the computer perceive, reason and act. On the other hand, Software Engineering (SWE) aims to support humans in developing large software faster and more effectively. This article gives the gigantic picture on the relationship between both SWE and AI and how can they contribute to each other.

Software Engineering

The main concern of SWE is the efficient and effective development of high-qualitative and mostly very large software systems. The goal is to support software engineers and managers in order to develop better software faster with (intelligent) tools and methods.

How do they overlap?

Both deal with modeling real objects from the real world like business processes, expert knowledge or process models.

How can AI contribute to SWE Research?

1)    Translation of informal description of requirements to formal descriptions: Using natural language processing.

2)    Code Auto-Generation: Generating code from detailed design descriptions.

3)    AI Testing: The diversity of test cases while testing a SW may cause a buggy release (as not all test cases could be applied). AI’s role here is applying only the sufficient test cases (instead of all the test cases) – just as humans do – to save time.

4)  Software Size Estimation: Estimating the size of a proposed SW Project using Machine Learning techniques.

How can SWE contribute to AI Research?

1)    Systematic Development of AI Applications

2)    Operating of AI Applications in real-life environments

3)    Maintaining and improving AI applications.

Intersection between AI and SWE ( from: AI and SWE - Current and Future Trends - Jörg Rech & Klaus-Dieter Althoff )

Sciences lying in the intersection

Agent Oriented SWE – Knowledge Based SWE – Computational IntelligenceAmbient Intelligence

References

Artificial Intelligence and SWE – Status and Future Trends

Artificial Intelligence Raining from “The Cloud” on Ubiquitous Computers!


Introduction

Welcome again! Today, we’re having a little chat about “Cloud Computing and its relation to both AI and Ubiquitous Computing”, a very interesting topic to me!

Cloud Computing

Cloud computing simply means that the programs you run and the data you store, are somewhere in a server around the world. You won’t bother yourself by storing any information on your personal computer or even use it to run a complicated program that requires sophisticated computers. Your personal computer will barely do nothing but upload the information to be processed or download the information you need to access. All the programs you will use will be web-based via the internet. Cloud computing is considered the paradigm shift following the shift from mainframe to client–server in the early 1980s.

If you look around you, you will figure out that cloud computing is taking over. Many of the desktop applications are turning to be web applications, as well as current Web Applications are getting more powerful. What really make good use of cloud computing nowadays are mobile cell phones, since they have relatively small processing powers and thus favor a lot from processing on the cloud instead. To understand more about the pros and cons of cloud computing visit this link.

Figure Illustrating Cloud Computing - Source : http://www.briankeithmay.com

The Effect of Cloud Computing on Computer Hardware Industry

I think that, Cloud Computing will lead to polarizing the computer hardware industry to 2 distinct poles: one pole is the giant servers that contain all the data and programs and work out all the processing of the clouds, and the other pole is the simple computer terminals with relatively minimal storage and processing power which use the clouds as their main storage and computation resource. This means that the hardware industry will not care about advancing personal computers’ hardware like it did before (as everything is done in the cloud)

AI as cloud-based services

Google has launched the cloud-based service Google Predication API that provides a simple way for developers to create software that learns how to handle incoming data. For example, the Google-hosted algorithms could be trained to sort e-mails into categories for “complaints” and “praise” using a dataset that provides many examples of both kinds. Future e-mails could then be screened by software using that API, and handled accordingly. (Technology Review Reference)

On the other hand, AI Solver Studios said they will be rolling out cloud computing services to allow instant access beside their desktop application AI Solver Studio. AI Solver Studio is a unique pattern recognition application that deals with finding optimal solutions to classification problems and uses several powerful and proven artificial intelligence techniques including neural networks, genetic programming and genetic algorithms.

How can Cloud Computing improve AI

Since Cloud Computing emphasizes that all the data as well as the programs running are stored somewhere in a cloud, this means that a large amount of data can be used for analysis and use by AI programs in order to perform data mining or other AI-related techniques to deduce useful information.

For example, consider the WordPress.com application, in which you have your own capacity to store on it what you need of posts and multimedia. If the data and the behavior of users – such as you – weren’t all stored in the cloud of WordPress.com, not enough data will be available to be used for AI purposes.

Thus I consider Cloud Computing to enhance the performance of AI by providing a lot of Data to be used by AI techniques.

Cloud Computing and Ubiquitous Computing

Cloud Computing is essential for Ubiquitous Computing (see my previous post to know more about it) to flourish. This is because most Ubiquitous computers will suffer from relatively limited hardware resources (due to their ubiquitous nature), this will make them really favor from the resources on a cloud in the internet.

Conclusion

There’s no doubt that merging the 2 trends (Ubiquitous and Cloud Computing) and supporting them with AI will result in tremendous technological advances. I think I will be talking about them more in the future!

My First Research Paper ! (To Be Published)


Greetings ! I wanted to share with you my first AI-related paper which will be published soon. I might (or maybe not) upload the whole paper in another post later to gain your reviews, but for now, I’m showing the abstract and keywords.

Abstract

Research in learning and planning in real-time  strategy (RTS) games is  very  interesting  in  several industries  such as military industry, robotics,  and most importantly game  industry.    A  Recent  published  work on online  case-based  planning in RTS Games does not include the capability of online  learning from experience, so the knowledge certainty remains  constant,  which leads to inefficient decisions. In this  paper,  an  intelligent agent model based on both online case-based planning  (OLCBP)  and reinforcement learning  (RL)  techniques  is  proposed.  In addition, the proposed model has been evaluated  using empirical simulation on Wargus (an open-source clone of  the well known Real-Time Strategy Game Warcraft 2).   This  evaluation shows that the proposed model increases the certainty  of the  case  base  by learning from experience, and hence the  process of decision making  for selecting more efficient, effective  and successful plans.

Keywords

Case-based  reasoning Reinforcement  LearningOnline  Case-based  Planning, Real-Time Strategy Games,  Sarsa (λ) learning, Eligibility Traces, Intelligent Agent.