C/C++ :: Variable Neigborhood Search With Simulated Annealing As Acceptance

Jan 1, 2015

i developed the code below to improve the solutions of a vehicle routing problem with a variable negborhood search. in this case one element is exchanged, i case no better solution is found two elements are exchanged and in case no better solution is found tree elements are exchanged with the funktions one exchange two exchange and tree exchange. as acceptance criteria the new solution is accepted if new solution <oldsolution or the criteria e^(newsolution-oldsolution)<u where u is a random number between 0 and 1. the code below is running but the solutions do not change at all from the solution bevore the change algorithnmus. to be more clear i have to say that first a starting solution is constructed and the solution after the exchange algorithm shouls be better thahn the start solution but although all loops are executed the solution stays the same.

how to imporve the exchange functions one exchange two exchange tree exchange so that a better solution in found.in the attachment you find a txt file from which the data is read in.

// library includes
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <map>

[code]....

View 13 Replies


ADVERTISEMENT

C++ :: Simulated Annealing Algorithm

Mar 10, 2014

I'm still a beginner at C++ programming, I have tried to implement some optimization algorithms (related to database) in C++, I cannot say it is going as far as I thought it will be, some errors does not even make sense, I will cut to the chase, I need to implement SA (Simulated Annealing) in C++, SA, which is an example of the Randomized Algorithms, functions on the concept of randomness and probability. In addition, I searched the internet with no (let say "accurate") code that might give me insight on how to begin, I only found one code for SA that I could understand, and edited it (which will be shown below), still looking to enhance and correct it more.

The code for SA is as follows:

Code:
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <cmath>

[Code] .....

If the concept of Simulated Annealing is not clear, you may refer to the following papers which can be found in a simple Google search: Simulated Annealing Algorithms: an overview.An Introduction to Interacting Simulated Annealing. Query Optimization (there is a sub-section for Simulated Annealing in this paper that explains SA briefly) ....

View 6 Replies View Related

C++ :: Simulated Radio Station Holding A Contest - Guess Number / Sequential Search

Dec 14, 2014

I have an assignment to write the code for a simulated radio station holding a contest. The contest is for a "caller" (user input obviously) to guess a number from 1 to 500. The "randomly generated" numbers are already chosen and are being stored in a .txt file. The code is to search for number guessed by the caller and if they are wrong, next caller until a caller is correct. The end result is to display the winning number, the indexed location the number was found, and how many callers guessed. This is what I have...

Code:
#include<iostream>
#include<fstream>
using namespace std;
int sequenSrch(const int prizeArray[], int arrayLength, int searchedItem);
int guess();

[Code] ....

I'm not sure if I am even on the right track... when I pass something into the sequenSrh(); the code compiles, asks for the number to be guessed and ends.

View 2 Replies View Related

C Sharp :: Search A Record In SQL Table Using Datetime Variable

Jan 1, 2014

I have an application in C sharp that searches for a record in a sql database using a datetimepicker,the output is displayed in a datagridview.When I execute it I got a blank datagridview with empty columns.I can not view the content and I don't get any error message.

Here is my code:

DataTable dt=new dataTable();
SqlDataAdapter sda=new sqldataadapter("select * from Delivery where convert
(char(20),Delivery_Date,112)='"+ dateTimePicker1.value.Date,con);
//con is sqlconnection
Sda.Fill(dt);
Datagridview1.DataSource=dt;

View 1 Replies View Related

C :: Sending Simulated Keyboard Input Into Running System Application

Nov 26, 2014

I'm trying to simulate a ctrl+ keypress into a running application.

Code:
#include <stdio.h>
int main (void) {
system("/usr/local/bin/rundb");
}

My problem is that the rundb program needs the user to type ctrl-b then s to actually start executing. What is the best way to handle this automatically? Some sort of fork/pipe?

View 3 Replies View Related

C++ :: Search And Find The Shortest Queue And Search After Some Condition?

Mar 7, 2013

I am trying to implement a Task scheduler where i have n number of tasks. The Idea behind my task scheduler is that in a loop of queues of a vector, task should get enqueued to the shortest queue among the loop of queues, which is done by the following code.

#include <vector>
#include <queue>
std::vector<std::queue<int> > q
int min_index = 0;
task t // implemented in the other part of the program

[Code] ....

Next i am trying to extend this paradigm to reduce the overhead time of the scheduler, Instead of searching the shortest queue every time, search after some condition ie. search the shortest queue after 5 tasks gets enqueued to the shortest queue.

i need to do something like this

#include <vector>
#include <queue>
std::vector<std::queue<int> > q
task t // implemented in the other part of the program
while(q[min_index].size()!=q[min_index].size()+5) // check whether current min_index queue's size is increased 5 more times if not goto enqueue

[code].....

View 1 Replies View Related

C++ :: Binary Search And Sequential Search Algorithm

Sep 16, 2013

Write a program to find the number of comparisons using the binary search and sequential search algorithms

//main.cpp
#include <cstdlib>
#include <iostream>
#include "orderedArrayListType.h"
using namespace std;
int main() {
cout << "." << endl;

[code]....

View 4 Replies View Related

C++ :: Binary Search Or Linear Search For 3D Array

Oct 7, 2014

inputting a search array. I tried putting a binary search but I can't get it to work. everything else works up until I put the value I am searching for in the array, then it just crashes.

How it suppose to work: input 2 coordinates with a value each then it calculates the distance between them then it suppose to let user search the coordinates for a value and state if found which coordinate it is at.

#include "stdafx.h"
#include <iostream>
#include <iomanip> //for setprecision
#include <math.h>

[Code].....

View 3 Replies View Related

C++ :: Type Conversion - Float Or Double Variable Into Unsigned Char Variable And Back

May 10, 2013

I would like to convert a float or double variable into unsigned char variable and back.

float number_float = 23.453f;
unsigned char* number_char = (unsigned char*)malloc(sizeof(float));
number_char = reinterpret_cast<unsigned char*> (&number_float);
float* number_float_0 = reinterpret_cast<float*>(&number_char);

I am not getting the same value back.. why?

View 2 Replies View Related

C++ :: Store A Reference Variable As Member Variable Of Interface Object

May 1, 2013

I am having trouble compiling my interface. I am trying to store a reference variable as a member variable of the interface object. Compiler says that the variable has not be initiated correctly.

LCD inherits from VisualInterface which is expecting a DisplayDriver object to be passed in (DisplayDriver is another interface, but thats not important).

I pass the displayDriver object in when LCD is instantiated in maininterfaces.zip

I was pasing it before as a pointer but was told that this could cause me problems with memory leaks and a reference was better, but now I cant seem to get it to compile.

View 11 Replies View Related

C++ :: Storing Variable Size Pointers Array As Class Variable

Mar 2, 2013

This problem is best explained by looking at its output below. I stored 15 different values but when retrieved some are wrong.

#include <iostream>
using namespace std;
class A {
public:
int ** pointer;

[Code] ....

I need to store and retrieve the 15 different values correctly. How to solve this? The main thing is, I need to store the pointer in class A objects.

View 6 Replies View Related

C++ :: Write A Loop Assigning Variable X To All Positions Of String Variable

Sep 8, 2013

I have to write a loop assigning a variable x to all positions of a string variable and I'm stuck. I don't have extensive experience with arrays and I'm also a bit confused about C-String. The problem is below.

"Given the following declaration and initialization of the string variable, write a loop to assign 'X' to all positions of this string variable, keeping the length the same.

char our_string[15] = "Hi there!";

(Please note this is a 'C-string', not C++ standard string.)"

View 5 Replies View Related

C :: Transform Local Variable Into Global Variable?

Oct 25, 2014

I need to transform a local variable into a global variable so I can use it in one of my functions. I thought about passing the value as a parameter to this function but I can do this since the function is called inside the while loop and this variable counts how many times the while loop does (so the final value is outside the loop). Example to visualize better:

Code:
while(condition) {
function(parameter1, parameter2);
count = count + 1;
}
printf("%d
", count);

So, I need to transform the final value of "count" into a global variable. Can I do this?

View 5 Replies View Related

C++ :: Store Function To A Variable And Call It Using That Variable?

Oct 15, 2013

I want to store few different functions to a variable for different structs/classes and then call it later using that variable, is it possible? something like

struct item {
int ID;
int special; // for function
};

item Key;
Key.special = UseKey(KEY_KING);

// now when I want to call function "UseKey(KEY_KING)" I want to use "Key.special", like this

if(iCurrRoom == ROOM_KING)
Key.special;
else if(iCurrRoom == ROOM_DRAGON)
Fireball.special;

View 5 Replies View Related

C/C++ :: Assign One Variable Address To Another Variable

Feb 3, 2014

I've been experimenting with pointers and am getting the below error.

'error: cannot convert 'int**' to 'int*' in assignment'

I thought it was ok to assign a variable address to another variable. Line 18 is where I get the error.

I am trying to show the progression of memory as I increment it as I have done on line 17 and again, I don't know why I don't see a progression through memory locations when output to the console on line 20.

Here's the code:
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
int main() {

int *tt = new int;
int *p = new int;

[Code] .....

View 6 Replies View Related

Visual C++ :: Creating A Variable Using A Variable?

Jun 16, 2013

Any way to create a variable using a variable in the name? So E.g. if you wanted to create an int named nr(x), and x was 1, you would get an int variable named nr1? How would you do this?

View 10 Replies View Related

C/C++ :: Change Enum Type Variable To String Type Variable?

Aug 10, 2014

How to change an enum type variable to a string type variable?

View 2 Replies View Related

C++ :: Difference Between Static Local Variable And Static Global Variable?

Aug 5, 2013

Here is the code,

Code:
class A {
};
A& CreateObject() {
static A a;
return a;
} static A aa;
int main() {
return 0;
}

So is there any difference between a defined in CreateObject and aa?

View 6 Replies View Related

C++ :: How To Search For Certain Value

Mar 28, 2013

I am having difficulties doing this program. i dont know how to search for the value 80.

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
class SortArray {

[Code] ....

View 1 Replies View Related

C++ :: How To Search For The Value 80

Mar 29, 2013

i am having difficulties doing this program. i dont know how to search for the value 80.

#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
class SortArray {
public:
int randomArray[];
int find(int randomArray[], int len, int seek);

[Code]...

View 1 Replies View Related

C :: How To Do Search In Struct

Jul 9, 2014

So i create a simple structure,that has a firstname, lastname, age, dateofbirth.I would like it if i type what I am searching for print out there is one or not.But i have some trouble with equals(in array).. i type in the same "keresettnev" as "tanulok[i].Firstname" but it thinks not the same. (it works with age..)

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct student {
char *Firstname[40];
char *Lastname[40];
int age;

[Code] ....

View 12 Replies View Related

C++ :: Search For The Key Given A Content In Map?

Jan 7, 2014

In a C++ map, is there any way to search for the key given a content? Example:

I have this map:

map<int,string> myMap;
myMap[0] = "foo";

Is there any way that I can find the corresponding int, given the value "foo"?

cout << myMap.some_function("foo") <<endl;

Output: 0

View 3 Replies View Related

C/C++ :: Passing Member Functions Member Variable To Another Variable

Aug 31, 2014

So I have a class object that contains the private member variable spot and the public member function MoveLock. Within MoveLock, is a member variable called numbers that holds the place where a user is on a "lock knob". Now, what I'm trying to accomplish is that whenever the user turns the "knob" in the wrong direction, the position is updated with that current numbers so that the clicks needed to unlock the first state is also updated. But I get these errors:

Error E2096 C:Users...switchtest.cpp 34: Illegal structure operation in function main()
Error E2294 C:Users...switchtest.cpp 39: Structure required on left side of . or .* in function main()

Ultimately, what I have in main() is a piece of what I'm going to implement in a class member function. I'm also thinking about moving the if else statements out of the for and creating a second one for the else portion.

#include <iostream>
#include <windows.h>
#include <iomanip>
using namespace std;
HANDLE inKeys = GetStdHandle(STD_INPUT_HANDLE);
HANDLE screen = GetStdHandle(STD_OUTPUT_HANDLE);

[code]....

View 10 Replies View Related

C++ :: How To Correct The Search In The End Of Program

Jun 1, 2013

Code:
#include<conio.h>#include<iostream.h>
class air_line {
private:
char name[5][100],name1;
long double opt,opt1,opt2,cnic[5],ticket_number[5],ticket_number1,cnic1;
public:
void input()

[code].....

View 1 Replies View Related

C++ :: Search Binary Tree

Aug 12, 2014

It has been a while since I built a binary tree from scratch so I decided to do it. Everything works fine but this one function. When I enter a number to search it just keeps running and allowing me to keep enter numbers.

Code:
void tree::search(int key,Node* leaf) {
if (leaf == NULL) {
std::cout<<"The tree is empty

[Code] ......

View 3 Replies View Related

C :: Depth-first Search Of A Graph

May 18, 2013

You have to implement a data structure to represent graphs,directed or undirected,that tries to avoid the wasted space in the representation of a graph with adjacency matrix and the difficulty of searching the edges with adjacency list representation.We consider that the vertices are numbered from 1 to nverts and the exit degree of each vertex is at most MAXDEG. If deg[i] is the exit degree of the vertex i then the neighbors of the vertex i can be saved at the matrix edge[i][j], 1<=j<=deg[i].

Write a program that reads the datas from a file: if the graph is directed or undirected(1 or 0), the number of vertices (nverts),the number of edges (nedges) and the first and the last vertex of each edge.Write the function dfs that, with argument the data structure that you implemented before for the representation of a graph, prints the edges by the depth-first search of a graph. What I've done so far is: I wrote a program that reads these information from a file, calculates the exit degree of each vertex and creates the matrix edge[i][j]. What data structure do I have to implement???

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved