Wednesday, November 24, 2010

Greedy knapsack problem

About knapsack problem the most important thing is that, you have to reorder the objects in descending order of profit per capacity or (Pi/Wi). When the reordering is done, then you can select the object one by one following that order. And it is guaranteed that order will produce the optimal solution for your knapsack problem. Here is the wiki link you want to read:
http://en.wikipedia.org/wiki/Knapsack_problem#Greedy_approximation_algorithm

Started thinking about Algorithms

I completed my undergraduate degree in B.Sc 2009. I am also getting President's Gold Medal for scoring the highest CGPA in the school, but what is my regret is that I don't have the programming achievement. Actually, I found that never learned an algorithm properly. In my 4th semester I got 4.00 out 4.00 with an A+ in Algorithm, but truth is that was just a grade. Algorithm was not properly absorbed in me what requires regular practice and troubleshooting, programming which I could not do properly for the rest 4 semesters of my varsity life. Now I am a lecturer of the same discipline and got some time to look at those algorithmic problems. I felt about this a long time ago, but I think I need to start from right now.....! Lets hope for the best.

Can I be a great programmer?

I completed my undergraduate degree in C.S.E. But still I cant demand myself as a great programmer. I think my approach towards programming was not the correct one and I found that after sometime of thinking algorithms came to me as a big complex thing. But this should not be like that and I am good at several scientific subjects like Math, physics and I spent a sufficient amount of time for math. So, what is needed for programming--is your interest for problem solving which is present in me. By profession, I am a software developer and I used to solve a lot of problems related to software development and I feel now I need to concentrate on core algorithmic matters. I used to introduced to all algorithms, now what I need is to master them properly. Lets pass some time often and on in programming just web development---what you say?

Can I be a great programmer?

I completed my undergraduate degree in C.S.E. But still I cant demand myself as a great programmer. I think my approach towards programming was not the correct one and I found that after sometime of thinking algorithms came to me as a big complex thing. But this should not be like that and I am good at several scientific subjects like Math, physics and I spent a sufficient amount of time for math. So, what is needed for programming--is your interest for problem solving which is present in me. By profession, I am a software developer and I used to solve a lot of problems related to software development and I feel now I need to concentrate on core algorithmic matters. I used to introduced to all algorithms, now what I need is to master them properly. Lets pass some time often and on in programming just web development---what you say?

Tuesday, November 23, 2010

Early Result for 2009-2010 Session

Recently CSE discipline is trying to publish the result a bit early than the previous time. Though the mark submission date was 10-11-2010, nobody was able to submit, but I think, we may be able to publish within 1st or 2nd week of the next opening of University. Anyway, it was a good initiative and most teachers already completed most of their script-checking by this vacation i think. We should keep it up.

How to get the path of AppData for an application?

Often in windows OS, a separate directory is created for an application for a user for saving user-specific information and user has the administrative right on that folder. Recently, I was working on a project with winxp platform. While client was testing the same software on win 7 , he found that the application failed to create the or modify a file in the system directory where the application was loaded. So, then the concept of Appdata came and I implemented the solution using the link provided by client.
Here is the link
http://stackoverflow.com/questions/946420/allow-access-permission-to-write-in-program-files-of-windows-7
And here is my code for getting the AppData folder

XmlDocument xmldoc = new XmlDocument();

string xmlfilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

//loading the file
xmldoc.Load(xmlfilepath + "/" + "enstatics.xml");
//returning the xmldoc
return xmldoc;

DNS setup in Ubuntu Linux

Recently, I assigned a project of setting mail server as network lab project for fourth year 1st term students. Anyway, no group came out with what I expected. Anyway, the first thing is here is needed is a successful DNS server.
Here is a post I created for DNS setup in Ubuntu Linux with BIND software.
DNS setup in ubuntu
Here is the link http://cseku.technopeople.net/setting-up-dns-linux.aspx

Working with xml file in C#

Well, Currently I am working with a project called webcam desktop application which mainly captures snapshot and video from the webcam. Before, starting the project, I had very little concept about how to do that and before me, an experienced developer worked on it. Anyway, my task was to fix the bugs. Whenever, I started bug-fixing, I found that previous coder used Appsetting to store information, which polls some static information from the system and nothing customization saved at run time, can be restored in the next run of the system. So, I came to plan to save the information in the xml file. Here I am going to show several things like


1. Creating xml file dynamically
2. Modifying the xml file
3. Reading from the xml file.

Creating XML file dynamically

//code for creating and saving default config
public void create_config_xml_file()
{
try {
//xml doc
XmlDocument xmldoc = new XmlDocument();

//xml declaration
XmlDeclaration xmldeclaration = xmldoc.CreateXmlDeclaration("1.0", "utf-8", null);

//create root element
XmlElement rootNode = xmldoc.CreateElement("myconfigdata");
xmldoc.InsertBefore(xmldeclaration, xmldoc.DocumentElement);
xmldoc.AppendChild(rootNode);

//adding more children to the root node

//imageformatindex
XmlElement ifiElement = xmldoc.CreateElement("imageformatindex");
ifiElement.InnerText = "1";
rootNode.AppendChild(ifiElement);

//currentdirectory
XmlElement currDirElement = xmldoc.CreateElement("currentdirectory");
currDirElement.InnerText = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
rootNode.AppendChild(currDirElement);

//fileprefix
XmlElement fpElement = xmldoc.CreateElement("fileprefix");
fpElement.InnerText = "ISeeStand";
rootNode.AppendChild(fpElement);

//filesuffixid
XmlElement fsElement = xmldoc.CreateElement("filesuffixid");
fsElement.InnerText = "2";
rootNode.AppendChild(fsElement);

//sequential
XmlElement seqElement = xmldoc.CreateElement("sequential");
seqElement.InnerText = "0";
rootNode.AppendChild(seqElement);

//sequentialvid
XmlElement seqVidElement = xmldoc.CreateElement("sequentialvid");
seqVidElement.InnerText = "0";
rootNode.AppendChild(seqVidElement);

//videncoder
XmlElement videncElement = xmldoc.CreateElement("videncoder");
videncElement.InnerText = "WMVideo9 Encoder DMO";
rootNode.AppendChild(videncElement);

//framesize
XmlElement fsizeElement = xmldoc.CreateElement("framesize");
fsizeElement.InnerText = "800 x 600 @5.00 fps";
rootNode.AppendChild(fsizeElement);

//framerate
XmlElement frateElement = xmldoc.CreateElement("framerate");
frateElement.InnerText = "5.00 fps";
rootNode.AppendChild(frateElement);

//getting appdata folder
string app_path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

//saving that document
xmldoc.Save(app_path+"/"+"enstatics.xml");

}
catch (Exception exc) {
MessageBox.Show("Failed to create the xml configuration file."+exc.Message);
}
}

From the above code, we can see how to use XMLDocument object and XmlNode for creating a XML file.

Modifying the XML file

The following code saves some info into the xml file accessing a particular XmlNode


//saving the image format index to the xml file
try {
XmlDocument xmldoc = MyStaticMgr.loadMyXMLDoc();
XmlNode formatIndexNode = xmldoc.GetElementsByTagName("imageformatindex")[0];
//setting the preferences to the xml node
formatIndexNode.InnerText = (ImageformatComboBox.SelectedIndex + 1).ToString();
//now saving the xml file
int result=MyStaticMgr.saveMyXMLDoc(xmldoc);
}
catch (Exception exc) {
MessageBox.Show("Failed to save the preferences"+exc.Message);
}

Reading from XML file

The following code will demonstrate how to access a particular node of the xml file for a particular information

//making a default choice
try {

XmlDocument xmldoc = MyStaticMgr.loadMyXMLDoc();
XmlNode formatIndexNode = xmldoc.GetElementsByTagName("imageformatindex")[0];
int format_index = int.Parse(formatIndexNode.InnerText);
//now setting that index to the combobox
ImageformatComboBox.SelectedIndex = format_index - 1;
}
catch (Exception exc) {
string messageBoxText = exc.Message;
string caption = "Exception Occurred";
MessageBox.Show(messageBoxText, caption);
}


From the above codes we found a particular section like this

XmlDocument xmldoc = MyStaticMgr.loadMyXMLDoc();

and

//now saving the xml file
int result=MyStaticMgr.saveMyXMLDoc(xmldoc);

Actually, MyStaticMgr is a static class which handles the basic operation like opening an xml document and returning the document object or saving the xmldocument object. Here is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace ISeeStand
{
public static class MyStaticMgr
{

//code for loading the xml document
public static XmlDocument loadMyXMLDoc()
{
XmlDocument xmldoc = new XmlDocument();
string xmlfilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//loading the file
xmldoc.Load(xmlfilepath + "/" + "enstatics.xml");
//returning the xmldoc
return xmldoc;

}

//code for saving to the xml file
public static int saveMyXMLDoc(XmlDocument xmldoc)
{
int saved = 0;
try {
string xmlfilepath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//loading the file
xmldoc.Save(xmlfilepath + "/" + "enstatics.xml");
//yes the file is saved
saved = 1;
}
catch (Exception exc) {
string messageBoxText = exc.Message;
string caption = "Exception Occurred";
MessageBox.Show(messageBoxText, caption);
}

//returning the result
return saved;

}



}
}

Thursday, November 4, 2010

Nostalgic Past

Sometimes I use to listen to the songs which I heard at least 9-10 years ago during my college life. Some of the songs remind me my golden time of life. A great inner-crying voice says to me if I could return to that past! Why can't we go back to past for few days, moments? I think Almighty should provide some power like this. Of course, there could be some logic and anti-logic against this, but life is not always a matter of logic, rather past is a matter of emotions too. While I listen to those songs, I feel like I am in that past, in that place with that age.......so nostalgic matters...!!

I remember my stay at JCC, that house, that fields, that academy blocks, my age, my thoughts staying at JCC everything. I forgot a lot of things and everyday I am forgetting gradually, but I will never forget my JCC, because that's the real emotional life for every cadet.

So, we people have both some aspiration to visit past and future of our life. Past soothes our mind and future reminds us hope for better.
May we go back to JCC again!!!