GPdotNET v2.0 announcement


GPdotNET tree based genetic programming tool

GPdotNET LOGO

After one year of silence in development of the GPdotNET, I may say this year will definitely be in focus of my GPdotNET project. At end of the 2011 year I started to develop on next version and I can say it will be very interesting.
– First of all the core library will be complete reformatted and implemented in order to get some improvements and better architecture, which will help to apply various specific engineering problems like optimization, and other specific problems.
– GPdotNET will be ported to MONO and Linux OS, and GPdotNET will become a multiplatform project(WIndows and Linux).
– It will be implemented more customization in odred to easly develop extensions for GPdotNET,e.g. Extended Fitness function, Terminal Set etc.
– The next version will use memory pooling for better performance in creating and reusing memory.
That is only some of the early announced features, and first beta release I hope to release in summer of this year.

So stay tuned

Advertisement

Kako zaokružiti iznos na 5 pfeninga u C#


Kao što je mnogima poznato u Bosni i Hercegovini ne postoji novčanica od 1 pfening, ali kada odete u granap često puta će te dobiti račun koji vam prodavačica ne može naplatiti jer ne postoje novčanice od 1 odnosno 2 pfeninga. Više informacija oko BH novčanica možete pogledati ovdje. Neki ovu pojavu iskorištavaju, a neki se pokušavaju prilagoditi na način da se na računu ne pojavljuju iznosi koji sadrže 1,2,3,4,6,7,8,9 pfeniga kao posljednju cifru računa.

U tu svrhu potrebno je standardno zaokruživanje koje postoji u C# poput Floor, Ceiling, Turncate obogatiti ovim bosanskim fenomenom te zaokruživati na najbliži broj 0 ili 5. U tu svrhu u narednom tekstu se nalazi implementacije metode koja ovu funkcionalnost implementira.

Potrebno je prvo iznos podjeliti sa 10 da se dobije vrijednost iza zareza u pfeninzima, a onda pogodnim ispitivanjima zaokružiti na bliži broj. Pogledajte implementaciju.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ZaokruzivanjeNaPolaPfeninga
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                             17.61, ZaokruziNa5Feninga(17.61m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.62, ZaokruziNa5Feninga(17.62m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.63, ZaokruziNa5Feninga(17.63m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.64, ZaokruziNa5Feninga(17.64m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.65, ZaokruziNa5Feninga(17.65m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.66, ZaokruziNa5Feninga(17.66m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.67, ZaokruziNa5Feninga(17.67m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.68, ZaokruziNa5Feninga(17.68m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.69, ZaokruziNa5Feninga(17.69m).ToString("N2"));
            Console.WriteLine(
                            "Iznos od  {0} KM se zaokruživa na {1}", 
                            17.70, ZaokruziNa5Feninga(17.70m).ToString("N2"));
            ///
            Console.WriteLine("Press any key to continue...");
            Console.Read();
        }

        private static decimal ZaokruziNa5Feninga(decimal iznos)
        {
            iznos *= 10;

            decimal cijelo = Math.Truncate(iznos);
            decimal ostatak = iznos - cijelo;

            if (ostatak < 0.29999999m)
                 ostatak = 0;
            else if (ostatak < 0.8m)
                 ostatak = 0.5m;
            else
               ostatak = 1m;

            return (cijelo + ostatak)/10.0m;
        }
    }
}

Using WCF Web API in .NET 4.5 and WCF 4.5


In previous posts we have seen some of the new features coming in the next version of .NET 4.5 and WCF 4.5. Today we are going to talk about new tool which simplifies the process of exposing data, services and application through the HTTP. This project is Codeplex project named as WCF Web API. Developing as an open source project, Microsoft want that developer and potential user can access and be part of the development process from the early stage to the final releases and integration to next version of .NET and WCF. Detailed information about WCF Web API you can find on http://wcf.codeplex.com site. As we mentioned with WCF Web API you dramatically simplifies the process of exposing data through service to consumers.

This blog post will describe how to use WCF Web API and to show how you can simply convert you existing WCF Data Service in to the service based on the WCF Web API, in just a few lines of code.

The most important features WCF Web API contains are:

-First-class programming model for HTTP in WCF
-Access HTTP from top to bottom
-Content negotiation
-HttpClient
-Out of the box support for XML, JSON and OData
-Typeless JSON support – Allows using a dynamic object on the server for accessing the body. Useful for jQuery clients.
-Plug in any format / media type
-IQueryable support – Supports OData’s URI format for services
-Designed for better separation of concerns and testability
-Validation, URI model binding, caching, etags, etc
-Easily integrate your IoC container
-Simple code-based configuration model
-Support for HTTP file upload and MIME-based batching
-Integrated Web API test client

Note that WCF Web API is working on the .NET 4.0 and Visual Studio 2010 as well, but with this post we want to show how such a technology works on the next version of .NET 4.5 and WCF 4.5. In fact, we will see how simply we can implement data service and expose it to ASP.NET application, or any client which can make request to the service in just few lines of code. To see simplicity of the WCF Web API, we will use existing WCF Data Service and convert it to the new version based on the WCF Web API. The existing project is demo developed for the last DevDays conference held in Sarajevo. The demo sample we are going to use here, you can download from this link. After you download the zip file, open it and you will get the content as next picture show.

The BugTracked Demo sample contains three folders:

-SQL Database –data tier and sql database for the project
-BugTrackerWCFClients – folder contains clients using the service
-BugTrackerService – folder contains WCF Service and EF DBModel project.

&For this demo we will use only DBModel. This is EntityFramework project which maps the tables from SQL database.

Now Open the Visual Studio 11 DP and create new ASP.NET empty application. Name it WCFWebAPISample, and click OK, similar as picture below.

Now that we have project we are going to use NuGet to install WCFWebAPI directly in to the project. Right Click on project and choose: Manage NuGet Package.

After WCF Web API installation, we need to copy existing EF project in to WcfWebAPISample solution folder and import it to the current WcfWebAPI Solution.

First Copy the folder in to Current solution folder:

If you haven’t installed NuGet you can install it from the following link. It also supports VS 11 beta, when the beta appear. Type WCF Web API in to search box and click on Install button of the WebApi.All.

After WCF Web API installation, we need to copy existing EF project in to WcfWebAPISample solution folder and import it to the current WcfWebAPI Solution.

First Copy the folder in to Current solution folder:

Return to VS 11 and Add existing project to current solution. After importing the project add the following reference to WCFWebAPISample project:
BugTracked.DBModel.dll
System.Data.Entity.dll


Note: Be sure that recently imported project is set to use .NET 4.5 instead of old .NET 4.0.

After we complete the importing BugTracker.DBModel project we need to setup database. Copy btdb database to you database folder and attach it to the SQL Server, or you can use Model First feature of the Entity Framework and create database to your SQL Server.
If you want to use Model First Feature connect to SQL Server as picture shows.

Create database and name it as BTDB, like the folowing picture:

Open BugTrackerEFDBmodel.edmx, right click and choose: Generate Database From Model…

Click Finish on the Wizard and complete SQL Script is generated for run.

Execute the script and the BTDB is created on SQL Server. Before we use it, wee need to fill some data. So that open every table and put at least one record in it, or just copy the data from the downloaded database.

Now the we have the Database and DBModel we can build our service to get manipulate data. If you look the existing project , we have created the WCF service project, implement Service interface, and service implementation. We have also implement Data Contract and define which data type can be exchanged thorough the service. We have also implement REST API for each Service operation, to be able to retrieve data by REST API. This was pretty big job, in comparison to what we are going to implement. To use our DBModel with WCF Web API, we need to implement one class, with BugTrackerWebAPI name.

The following code represent implementation for the class:

The class is decorated with [ServiceContract], and operation with [WebGet], attribute and this is all we need to implement. This two attribute replace whole implementation of WCF Service. The last thing wee need to implement before we runt the app is route registration in to Global.asax.

Add new item, choose Global.asax, and write just only one line of code, showed in the following picture:

We only register Api/bug route to Service implementation. This rout we need to put in to project property to be able to run the service immediately when browser appears. The picture below show this step.

After we run the application browser shows our data in XML format:

As we have seen this is very easy implementation of the Service data, without any configuration setting, DataContract and other WCF specific feature. On this way WCF becomes very hady tool in lighter application architecture, which was not the case in previous versions.

The complete implementation of this Demo you can download from here.