Monday, July 1, 2013

BubbleSort in JAVA

ArrayBub.Java Class

public class ArrayBub {

private long[] a;
private int nElems;

public ArrayBub(int max){
nElems = 0;
a = new long[max];
}

public void insert(long value){
a[nElems++]= value;
}

public void display(){
for(int i=0;i<nElems;i++){
System.out.print(a[i] + " ");
}
}

public void bubbleSort(){
int out, in;

for(out= nElems -1; out > 1; out--){
for(in=0;in<out;in++){
if(a[in] > a[in+1]){
long temp = a[in];
a[in] = a[in+1];
a[in+1] = temp;
}
//swap(in,in+1);
}
}

}

private void swap(int one, int two){
long temp = a[one];
a[one] = a[two];
a[two] = temp;
}

}

----------------------------------------------------------------------------------------------------------------------------------
BubbleSortApp.java class

public class BubbleSortApp {

public static void main(String[] args) {

int maxSize = 100;
ArrayBub  bub;
bub = new ArrayBub(maxSize);

bub.insert(77);
bub.insert(43);
bub.insert(99); // insert 10 items
bub.insert(44);
bub.insert(55);
bub.insert(22);
bub.insert(88);
bub.insert(11);
bub.insert(00);
bub.insert(66);
bub.insert(33);
bub.display();

bub.bubbleSort();
System.out.println("");
bub.display();
}

}


Saturday, April 27, 2013

Hash Table Separate Chaining and Open Addressing Program in CPP/C++



#include <iostream>
#include <fstream>
using namespace std;

int aryi=0;

template <class T>
class Node{
public:
T data;
Node<T> * Next;

Node(){
data = aryi++;
Next = NULL;

}
};

template <class T>
class List{
public:
Node<T> * head;

List(){
head = new Node<T>;
}

void addnode(int & x){
Node<T> * cur = head;
if(cur==NULL){
//For first node
cur->data = x;
cur->Next = NULL;
}
else{


while(cur->Next != NULL){
cur = cur->Next;
}
//New Node Creation
Node<T> * NewNode = new Node<T>;
NewNode->data = x;
NewNode->Next = cur->Next;
cur->Next = NewNode;


}
}

void showdata(){
Node<T> * cur = head->Next;
while(cur!=NULL){
cout<<"--"<<cur->data;
cur=cur->Next;
}
}
};

int convertasc(string & word){

int asc = 0;
int total = 0; //FOR TOTAL THE WHOLE WORD IN ASCII

for(int i=0; i< (int)word.length(); i++){

asc = (int) word[i];
total += asc;

}

return total;
}

template <class T>
class OpenAddr{
T totsize, modin;
T * ary;

public:
OpenAddr(T modindex, T size){
ary = new T[modin];
modin=modindex;
totsize=size;
}

void createHash(string & word){
int total = convertasc(word);
int mod = total % modin;

ary[mod] = total;
}

void displayOpenAddr(){
for(int i=0; i<modin; i++){
cout<<"--"<<ary[i]<<"--\n";

}
}

void searchOpenAddr(string & word){
int total = convertasc(word);
int mod = total % modin;

if(ary[mod] == total){
cout<<"\nString :: "<<word<<" :: Index :: "<<mod;
return;
}else
cout<<"\n STRING NOT FOUND";
}
};

template <class T>
class SEPChain{
List<T> * ary;
T totsize, modin;


public:
SEPChain(T modindex, T size){
ary = new List<T>[modindex];
modin=modindex;
totsize=size;
}

void creatHash(string & word){
int total = convertasc(word);
int mod = total % modin;
ary[mod].addnode(total);
}

void displaySEPChain(){
for(int i=0; i<modin; i++){
Node<T> * curr = ary[i].head;
while(curr != NULL){
cout<<"--"<<curr->data;
curr = curr->Next;
}
cout<<"\n\n";
}
}

void serachSEPChain(string & word){
int total = convertasc(word);
int mod = total % modin;

Node<T> * curr = ary[mod].head->Next;
T index = 0;
while(curr != NULL){
if(curr->data == total){
cout<<"\n"<<"String :: "<<word<<" :: Index :: "<<mod<<" :: Chain Index ::"<<index;
return;
}
index++;
curr = curr->Next;
}
cout<<"\n String NOT FOUND\n";
}
};
int main(int argc, char **argv)
{
if(argc < 2){
cout<<"\n Please Enter a File Name:\n\n\n";
return 0;
}
argv++;

fstream input(*argv);
string word;
int count = 0, modindex;
cout<<"Your Input::->> ";
while(input>>word){
cout<<word<<" ";
count++;
}
cout<<"\n";
modindex= count * (0.75);

if(modindex < 1){
modindex = 1;
}

SEPChain<int> SEPC(modindex,count);
OpenAddr<int> OpenC(modindex,count);

cout<<"\nseparate chaining:\n";
fstream inp(*argv);
while(inp>>word){
SEPC.creatHash(word);
OpenC.createHash(word);

}

SEPC.displaySEPChain();

cout<<"\nOpen Addressing with Replacement:\n";

OpenC.displayOpenAddr();

cout<<"\nSearch Indexing of the string (both Sep. Chain & Open Addressing with Replacement:\n\n";
fstream in(*argv);
while(in>>word){
SEPC.serachSEPChain(word);
OpenC.searchOpenAddr(word);
cout<<"\n\n";
}


return 0;
}

Breadth First Search (BFS) and Depth First Search (DFS) Program in C++/CPP


#include <iostream>
#include <fstream>

using namespace std;


template <class T>
class Stack{
private:
int max_size, top;
T * list;
public:
Stack(T size){
max_size = size;
top = 0;
list = new T[max_size];
}
bool isEmpty(){
return (top <= 0);
}
bool isFull(){
return (top >=max_size);
}
void push(const T& item){
if(!isFull()){
list[top] = item;
top++;
}
}
T pop(){
if(!isEmpty()){
top--;
}
return list[top];
}

T Top(){
return list[top-1];
}
};

//Queue Implementation
template <class T>
class Queue {
private:
int Qmax, count, Qf, Qr;
T * list;

public:
Queue(int size){
Qmax = size;
Qf = 0;
Qr = Qmax - 1;
count = 0;
list = new T[Qmax];
}

bool isEmpty(){
return (count == 0);
}

bool isFull(){
return (count == Qmax);
}

void addQueue(const T &element){
if(!isFull()){
Qr = (Qr + 1 ) % Qmax;
count++;
list[Qr] = element;
}
}

T FindFront(){
return list[Qf];
}

T DeleteQueue(){
T x;
if(!isEmpty()){
x = list[Qf];
count--;
Qf = (Qf + 1) % Qmax;
return x;
}else
return 100;
}


};



void revisit(int *visited, int size){
for(int i=0; i<size; i++){
visited[i] = 0;
}
}

int main(int argc, char **argv)
{
if(argc < 2){
cout<<"\n Please Enter a File Name:\n\n\n";
return 0;
}
argv++;

fstream input(*argv);  //Input as a file name at run time( from command line)

int size;

if(input>>size) cout<<"\nMatrix of: "<<size<<"*"<<size<<endl;
else return 0;

int adjmat[size][size];
int visited[size];

for(int i=0; i<size; i++){
for(int j=0; j<size; j++){
input>>adjmat[i][j];
}
}



cout<<"\nAdj. Matrix:\n";
for(int i=0; i<size; i++){
for(int j=0; j<size; j++){
cout<<adjmat[i][j]<<" ";
}
cout<<"\n";
}


//BFS(adjmat,size,visited);
cout<<"\n\nBreadth First Search:\n";
revisit(visited,size);
Queue<int> bfs(size);
{
int v = 0, w ;

bfs.addQueue(v);
visited[v] = 1;


while(!bfs.isEmpty()){

w = bfs.DeleteQueue();

cout<<w<<"--";

if(w==100){continue;}

for(int i = 0; i<size; i++){
if(adjmat[w][i] == 1 && visited[i] == 0){
bfs.addQueue(i);
visited[i] = 1;
}
}


}
cout<<"\n";
}
//bfs code ends here


//DFS Code Starts From Here
cout<<"\n\nDepth First Search:\n";
Stack<int> dfs(size);
revisit(visited,size);
{
int v = 0;
cout<<v<<"--";
dfs.push(v);
visited[0] = 1;

while(!dfs.isEmpty()){

for(int i=0; i<size; i++){
if(adjmat[v][i] == 1 && visited[i] == 0){
cout<<i<<"--";
dfs.push(i);
visited[i] = 1;
v = i;
i=0;
}
}

v = dfs.pop();

}
cout<<"\n";
//DFS Code ends Here



//Biparted Graph
{
revisit(visited,size);
int colored[size];
revisit(colored,size);
Queue<int> Bipart(size);
int v = 0, x;
visited[v] = 1;
colored[v] = 3;

for(int i = 0; i<size; i++){
if(adjmat[v][i] == 1 && visited[i] == 0){
Bipart.addQueue(i);
visited[i] = 1;
colored[i] = 4;
}
}

while(!Bipart.isEmpty()){
x = Bipart.DeleteQueue();
for(int i=0; i<size; i++){
if(adjmat[x][i] == 1 && visited[i] == 1 && colored[x]==colored[i]){
cout<<"\n\n Not a Biparted Graph\n\n";
return 0;
}
}

for(int j=0; j<size; j++){
if(adjmat[x][j] == 1 && visited[j] == 0){
Bipart.addQueue(j);
visited[j] = 1;
if(colored[x] == 3){
colored[j] = 4;
}else colored[j] = 3;
}
}
}

cout<<"\n\nBiparted Graph\n";

}
//Biparted graph ends here
}
return 0;
}

Problem Description: Food Chain Management System


Food Chain Management System

The computerized system which holds and keep the digitized record of all the tiny and vital processes including farming food, keeping them into bifurcated categorized raw material, make available to factories and shape it to the final product to the customer. Food chain management system is all about the food supply and its management. There are numerous companies which provide the services of FCMS. McDonalds, KFC, Nutrilite, Dominos, Pizza Hut, Reliance Fresh, Star Bazar, Futurebazaar, Reliance Mart, are one of the giant FCMS companies working in India. The progression of FCMS starts from the food market yard. Farmers vend their sowed product to the massive corporate companies. The FMCS keeps all the track record of this raw material including its prices, weights and many other properties. Then this raw material is ready to convert and start towards the final shape of the product. So the system decides the quantity of raw material for the each factory as per the demand of that particular product. FCMS also keeps the record of production, distribution and retails. To understand the process of the FCMS, we need to understand and study the process of the any one commercial giant. So let me elucidate the process of Reliance Fresh. Reliance Fresh buys the vegetables, fruits and other goods from the farmers and comprises them under the Reliance brand and sells it to the clienteles. Reliance Fresh itself contains sub FCM systems under one roof of own FCMS. They offer many FCMS products like Maggi, Nutrilite, Parle, Britannia, Sunfeast, and many more. The computerized system gives the flexibility to maintain the food and its distribution and sells. It is easy to find the total sales amount, analyze the data and procedure that to make an edifying grid of retail.
Food is the critical item in supply chain management. Essential guidelines pertaining to distribution need to be strictly followed by respective food or Beverages Company to reach to the consumer market. There has to be other major roles in food chain whether it is processed food or unprocessed food. There is always urgent need to take actions towards process integration along with the value chain to the organization of flexible and responsive network. Cooperation and integration could focus on many different functions such as planning, quality management, research, logistics, knowledge, sales, procurement, information management, marketing, packaging, production, etc.

The Actors who represents their active or passive role in Food Chain Management are suppliers, primary producers, processors, manufactures and retailers which have consumers as the final customers. Its strategic development and operational improvements involves long term commitment and major investment. A specific strategic development concerns about huge amount investment in electronic network for tracking and tracing food. Even the major concern is to provide cost effective and consistent food product to consumers without affecting basic price. It is crucial for organization to build a low-cost supply chain operation which takes costs out of the system and in turn gives them greater pricing flexibility in the marketplace. Reliable and cost effective supply chain management plays an important role in the area of cost. Today’s scenario gives us roughly idea about nearly 40% of the customers place their order either from home or office. Promotional cost also plays important role in food chain management. Instead of parking huge investment in prime locations they need to manage call centers to bring better result. The organization needs to effectively distribute job responsibilities to various processors. The other way is to outsource the partially processed product from different processors but it might increase the cost of finished product.
An Organization needs to focus on changing consumer needs. In order to sustain in capricious environment they must have to adapt new developments in technology, production, management, communication, organization or cooperation and on the establishment of trust between all stakeholders along the food chain including consumer.
Here below is the model of Food Chain from Farm to Store which shows us what is exactly going on practically?







Food Chain Management System (FCMS) has four stages:
1.      e procurement
E-procurement (electronic procurement)or supplier exchange is the business to business  or  business-to-consumer  or business-to-government purchase and sale of  supplies, work, and  services through the Internet as well as other information and networking systems, such      as electronic data interchange and enterprise resource planning. E-procurement is done with a software application that includes features for supplier management and complex auctions. The new generation of e-Procurement is now on-demand or a software-as-a-service (SaaS). The e-procurement value chain consists of indent management, eTendering, eAuctioning, vendor management, catalogue management, and contract management. Indent management is the workflow involved in the preparation of tenders. This part of the value chain is optional, with individual procuring departments defining their indenting process. In works procurement, administrative approval and technical sanction are obtained in electronic format. In food procurement, indent generation activity is done online.
2.      Warehousing
A warehouse is a commercial building for storage of goods. Warehouses are used by manufacturers, importers, exporters, wholesalers, transport businesses, customs, etc.
3.      Transportation
4.      Retailing


RETAIL POSSESSION IN INDIA
Ideology in the retail commerce is considered to be exclusive element of the Indian neighborhood hundred and thousands of bazaars, mandis and haats are located across the full length and span of India by people’s self-management and managerial capability. From weekly markets, to fairs and village melas, to the appearance of the mom-and-pop stores (kirans) across region, to the organization of public allocation through ration shops, finally the commercial retail formats stepped into the attention witch include restricted product outlet, supermarkets and hypermarkets, shopping malls and subdivision stores. India’s retail sector countryside has been undergoing a conversion and is the fastest increasing sector in the Indian economy. The entire landscape of organized retail in India has experienced the varied formats of food retailing such as the supermarkets, hypermarkets, departmental stores and neighborhood.


FARM TO FORK MODEL


The path from food source to the point of final service is called the farm to fork continuum. The source is where the food item originates. This could be a farm where produce is grown, a sea from which fish are harvested, a dairy farm or beef cattle operation, and so on. It could also be freshwater aquaculture.
Processing/manufacturing includes all the steps along the food chain that prepare a food item for distribution. In the case of produce, this encompasses everything from washing produce and preparing it for sale, to pasteurization or low acidity canning.
Distribution includes everything from storage and warehousing, repacking, reprocessing, and transport to the next point in the continuum. Sometimes distribution involves multiple points.
Point of final service includes every place where food is purchased and/or consumed, from delis, cafeterias, restaurants, grocery stores, and so on, to the home.








Point of Final Service (Food Establishment System)

 

Each point along the farm to fork continuum represents its own unique system. For example, a restaurant is an example of a system.

The outcome of the system (food served to customers) is influenced by inputs (such as ingredients, organisms, chemicals) and processes (such as storing, preparing, cooking, and serving) that make up the system. Internal system variables such as food workers, equipment, and the economics also influence the outcome.
EHS-Net uses system theory to identify environmental antecedents (underlying factors) to illness and disease outbreaks.
The software is quickly becoming a must-have solution for businesses with complex labor needs, including those that employ a large number of workers who get paid on an hourly basis.
Food Markets, a privately-owned retail grocer operating many stores, is one of these businesses. Food market was utilizing multiple, non-integrated applications to oversee its scheduling and workforce management processes. This time-consuming system resulted in difficulty controlling overtime and trouble comparing an employee's scheduled hours to their actual hours.

To remedy these issues, Food Markets decided to adopt an integrated and comprehensive workforce management solution. Within months, the food store chain and a workforce management company called JDA had implemented the system in all of the company's locations.
Using the software, Food market is now able to monitor the each store's sales-per-labor hour numbers and make staffing adjustments as needed. The solution uses POS and customer traffic information to forecast potential workforce needs in 15-minute intervals. Food market effectively reduced its labor-scheduling process by as much as 75 percent and lessened overtime by more than 4,000 hours in the first quarter of 2009, according to a JDA case study. Furthermore, the chain of stores was able to use the workforce management software to lower labor costs by 10 to 15 percent due to a "minimum hours" policy that was instituted. Food market also reported that the workforce management software helped increase store manager visibility, enhance worker productivity and accelerate checkout time. In addition, the solution was found to improve customer service by assuring that an adequate number of employees are always on the floor and at the registers.

The vegetables were collected from farmers and brought to collection centers where payments and quality checks were done. These units were then transferred to the processing and
Distribution centers with the help of Reliance’s own logistics. The products having processed here were then distributed to the various local Reliance fresh outlets. The product range offered by Reliance Fresh at its outlets is as given in the exhibit below..

From the point of view of the store operation excitement among the people who there was a decline in no of people visiting the precarious situation and forced them to revisit their long term strategy. People started comparing the fate of Reliance Fresh with other existing retail stores which were not doing well due to the some reasons: Operating costs were very high. Rent for shops at prime areas, salaries of supplyions and given to stir such opposition, all standalone food & grocery stores.

Food Chain Management is a web based grower record system for crop and field based activity records, for managing large numbers of individual growers.  The application allows growers to maintain and update individual crop records, specifically pesticides and fertilizers, to ensure safe use is monitored and assured.
The software gathers all field information and enables the grower to upload and manage all fields and farms and audit chemical applications against pesticide protocols.
With the increased need to access and input data from any location, Food Chain Management embraces the latest handheld technologies, delivering instant information at the point required, so whoever undertakes the task – and wherever they are based – routines are completed quickly and efficiently and transferred rapidly, avoiding unnecessary duplication of effort and speeding up operational processes.

System has comprehensive, easy-to-use, farm recording solutions that manage all aspects of crop production, in a harsh outdoor environment. The system, a web-based Grower record system for crop and field based activity records for managing large numbers of individual growers. The system is a PC and mobile based recording system for the management of all aspects of crop and field based activities.  Assists and manages the burden of legislative compliance for agronomists and farmers.
Food management system T&T (Track and Trace) is a complete pack house management system. It is flexible and modular in design - therefore suitable for both small pack-houses with simple processes, and larger multi product pack houses with complex multi product operations. From raw material to final product, processes can be accurately controlled and monitored to drive out waste and costs and deliver full traceability. Integration data provides the invaluable link in the traceability chain from pack-house back to grower site. New or existing back office finance or ERP solutions can be integrated to deliver the ideal pack-house management solution. With its ability to consolidate and manage large quantities of uniquely referenced data, Green light Track and Trace ensures essential information is accessible at any point in the procurement process. This enables it to be instantly modified and updated, reinforcing the entire information process from quality management through to the control of logistics. With the increased need to access and input data from any location, Green light embraces the latest handheld technologies, delivering instant information at the point required, so whoever undertakes the task – and wherever they are based – routines are completed quickly and efficiently and transferred rapidly, avoiding unnecessary duplication of effort and speeding up operational processes. Intelligent auditing features constantly check conformity and compliance against any given specifications, minimizing error and reducing risk. So, at every point, Greenlight can help you to monitor a consignment’s status and security, confirm its past and control its future.

 As we have studied the various problems and workflow of the food chain management system, the process from farm to fork is managed by the central computerized system. The raw material from the farmer passes to the supplier and to the factory to shape it to the final product and the product is served with the any famous brand name which handles the food chain management system.