I am trying to develop the genetic algorithm to solve Traveling Saleman problem and part of my challenge is to generate random tours long enough and write a fitness function to evaluate the cost incurred for each of the random tour. I have attempted to write the following. My objective is to generate random tours from the city to city distance matrix without any repetitions in the tour. The random function should return a tour without any cities repeating twice. Please can any one help me with the logic for this problem: class ran { public static void ranper(int n, …

Member Avatar
Member Avatar
+0 forum 6

I have been asked to build a group of functions that carry out set theory operations such as intersection and union. The functions below that I must complete are set_intersectWith, set_unionWith, set_minusWith, set_powerset, where: > set_intersectWith = A ∩ B > set_unionWith = A ∪ B > set_minusWith = complement = A \ B > set_powerset = P(S) The following file is what I am working on, *set.c*: #include <assert.h> #include <stdlib.h> #include <stdio.h> #include "clist.h" #include "set.h" struct set_implementation { clist * items; printer item_printer; equals item_compare; }; set * new_set(printer item_printer, equals item_compare) { set * s = …

Member Avatar
Member Avatar
+0 forum 1

These programs are not perfect and very coarcenes but I think it understandable for who are new to learning Graph Theory. I will point directly each problem by using example code. Any questions or idea please post here. Thank you. Here are my programs, we will start with a basic problem: **1) Depth-first Search (DFS) without using marking array.** In this program, I used record "point" for demonstrate Adjacency List of the Graph. program DFS; const fi='DFS.ip'; fo='DFS.op'; ma=100; type point=record //each point mean a vertex of the Graph cn:array[1..ma] of byte; //connected vertices with "point" deg,def:byte; //deg: degree of …

Member Avatar
Member Avatar
+2 forum 1

I would like to propose a link thread for posting listings of sites on CS topics not tied to a specific language. Two that come to mind as being relevant to some of the more common questions would be the [OS Dev Wiki](http://www.osdev.org), and the similarly themed but less established [Compiler Dev Wiki](http://www.compilerdev.com/). [Rosetta Code](http://rosettacode.org/wiki/Rosetta_Code) would also be relevant, for comparisons between languages and paradigms. A few others to start with might be: * [The Dictionary of Algorithms and Data Structures](http://xlinux.nist.gov/dads/) * The [Portland Pattern Repository](http://c2.com/ppr/), home of the original WikiWikiWeb as well

Member Avatar
Member Avatar
+1 forum 2

i was searching for a code to perform binary XOR addition. Exams coming up, and needed to a quick way to create and verify standard array tables. However, i didnt find anything substantial on the internet, so made my own version of it. can anyone take a look and tell me if there's some other(better) way to do this? thanks in advance for your time :) somjit. here's the code: #include<stdio.h> #include<string.h> int main(){ int *stop,decNum1=0,decNum2=0,result=0,ip_base=2,flag=0,i=0,binLength=0,temp=0,opResult[15]; char num1[15],num2[15]; puts("\n"); do{ printf("enter two binary numbers of same length(<15):\n"); printf(" enter 1st binary number: "); fgets(num1,15,stdin); binLength=strlen(num1); decNum1=strtol(num1,&stop,ip_base);// decNum1 is the dec …

Member Avatar
+0 forum 0

I am currently working on kind of multi-graph structure. The thing is that two graphs are needed for my application which span the same vertices but with two distinct set of edges (i.e., a multi-graph). The first graph is a binary search tree, while the second graph must be general (directed / undirected, or bidirectional, possibly with cycles, etc.). The B-tree is used for fast queries of nearest nodes, while the second graph is needed for path-planning (e.g., in the style of shortest-path algorithms). Both graphs have to be completely mutable (reconnections, moving nodes around, adding/removing nodes and edges to …

Member Avatar
Member Avatar
+0 forum 12

I was recently toying with an idea from my education in computer science, namely that any deterministic algorithm can be expressed with just two control structures: a loop containing a switch. I never doubted it. From a certain point of view, that's what programs look like to the silicon of a CPU. The switch variable is the PC, and the switch case is the instruction at that address. Nevertheless, I decided to play with it. I decided to use a legacy program I've done a few other things with, namely the original Hunt the Wumpus game from Creative Computing. Look …

Member Avatar
Member Avatar
+0 forum 2

This code is giving me runtime error. Here, first I want to take a integer input which determine the number (n) of nodes in the graph. Then for n-1 time I want take two integer input which will give the adjacency information. [CODE] #include <set> #include <map> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <cctype> #include <cstdio> #include <string> #include <vector> #include <cassert> #include <cstdlib> #include <cstring> #include <sstream> #include <iostream> #include <algorithm> #define MAXEDGE 1000 using namespace std; typedef struct{ int linked_to; }edg; typedef struct{ edg edge[MAXEDGE]; bool visited[MAXEDGE]; int total_nodes; }graph; int …

Member Avatar
Member Avatar
+0 forum 6

Hey, I am a programmer in PHP Procedural and have just applied for a new job to further my career as a PHP Programmer, however they said it's advised to learn PHP OOP... so I have been watching some tutorials about PHP OOP and it just looks like OOP is making procedural code 10x longer for no reason..... Whats the point in learning OOP when it does nothing that procedural programming doesn't do it seems? It just seems like your wrap a load of functions in a class why not just have functions...... Anyone shed some light on this? Dan

Member Avatar
Member Avatar
+0 forum 3

so I recently wrote a function that sorted using the last value in a tuple. Obviously this couldn't be done simply say sorted(tuples, key=tuples[-1]) because that is not a "legal" call. However I did run across, while trying to figure out how to make things like this work, the utilization of lambda so the code became. [CODE]def sort_last(tuples): x=sorted(tuples, key=lambda tuples: tuples[-1]) return(x)[/CODE] The code runs correctly and, that's all well and good, but I don't understand why lambda tuples"or any given var for that matter":. makes this possible. Can someone explain this to me in a way I'll understand …

Member Avatar
Member Avatar
+0 forum 6

Hello Friends, I was reading about the orthogonality and it's advantages. Then heard something like "Java is an Orthogonal Language". Can anyone explain me what do we mean by a particular programing language being orthogonal? If I am using Java for development of my application, does it imply that my application is Orthogonal?

Member Avatar
Member Avatar
+0 forum 2

Hi , these days I'm reading the brans kernel development tutorial. and doing it's particles. So last I find to had to read Intel 80386 programmers manual by intel. In section 2.6 Interrupts and Exceptions I asking a theoretical question here. They said Exceptions are synchronous and Interrupts are asynchronous. what that means precisely ? Is that mean's that interrupt even can be happen middle of a instruction , but exceptions can't happen like that ? Please correct me if I'm wrong.

Member Avatar
Member Avatar
+0 forum 3

With technology and actually with anything else, adoption of the new item or technology takes times and lots of effort. With the adoption of social media at fast speed, I truly believe that now the laggards are embracing it. You are seeing older generations on Facebook. One important fact is that technology has become commonplace in society and it will not be obsolete, like my lovely BetaMax or Commodore 64. So what do you think about this? [LIST] [*]the first 2.5% of the adopters are the "innovators" [*]the next 13.5% of the adopters are the "early adopters" [*]the next 34% …

Member Avatar
+0 forum 0

The End.