473,395 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

euler circuit

Hello,
could anyone help with euler circuit ? I tried to find it, found some,
but they are not working. Tried to write my own one, but it supposed
to be slow with big graphs because it trying all possibles situations.
Prefer to get something on c++ or java, but other languages are
welcome also.
Tnanks

Mar 19 '07 #1
7 6840
dk*******@gmail.com wrote:
Hello,
could anyone help with euler circuit ? I tried to find it, found some,
but they are not working. Tried to write my own one, but it supposed
to be slow with big graphs because it trying all possibles situations.
Prefer to get something on c++ or java, but other languages are
welcome also.

Your question is answered here:
http://www.parashift.com/c++-faq-lit...st.html#faq5.2

Mar 19 '07 #2
On Mar 19, 3:52 am, red floyd <no.s...@here.dudewrote:
dkulta...@gmail.com wrote:
Hello,
could anyone help with euler circuit ? I tried to find it, found some,
but they are not working. Tried to write my own one, but it supposed
to be slow with big graphs because it trying all possibles situations.
Prefer to get something on c++ or java, but other languages are
welcome also.

Your question is answered here:http://www.parashift.com/c++-faq-lit...st.html#faq5.2
Or here:
http://www.parashift.com/c++-faq-lit...t.html#faq-5.2

Mar 19 '07 #3
The problem is, that I did that program, and it is finding euler
circuit. But it is not good because the algorithm was written by
myself.

Mar 19 '07 #4
On 19 Mar 2007 05:41:26 -0700, dk*******@gmail.com wrote:
>The problem is, that I did that program, and it is finding euler
circuit. But it is not good because the algorithm was written by
myself.
Show your code, so it may be commented

Zara
Mar 19 '07 #5
It might be not the smart one, but... I tried to translate into
English language, but I haven't check, because I just reinstalled my
OS and don't have anything installed on it yet. I put not english, but
working source after this one.

package euler;

public class Programa
{
static int graphs[][];
static int i1, j1;
static int which;
static int till;
static int the_end;
static int routes;
static int edges;
static int cik = 7;

public Programa()
{
graphs = new int[cik][cik];
}

public static void main(String[] args)
{
Programa a = new Programa();
a.formatArray();
edges = a.nEdges();
a.indexs();
int how_much = a.hm();
boolean tess;
for (int i = 0; i < 1000; i++)
tess = a.way(1);
}
public void formatArray()
{
for (int i = 0; i < cik; i++)
for (int j = 0; j < cik; j++)
graphs[i][j] = 0;

graphs[0][1] = 1;
graphs[0][5] = 1;
graphs[0][3] = 1;
graphs[0][6] = 1;

graphs[1][0] = 1;
graphs[1][2] = 1;

graphs[2][1] = 1;
graphs[2][3] = 1;
graphs[2][4] = 1;
graphs[2][5] = 1;

graphs[3][0] = 1;
graphs[3][2] = 1;
graphs[4][5] = 1;
graphs[4][2] = 1;
graphs[5][0] = 1;
graphs[5][2] = 1;
graphs[5][4] = 1;
graphs[5][6] = 1;

graphs[6][0] = 1;
graphs[6][5] = 1;
}
void indexs()
{
formatArray();
int hm = 0;
for (int i = 0; i < cik; i++)
for (int j = 0; j < cik; j++)
{
if (graphs[i][j] == 1) hm++;
}
}

int hm()
{
int a = 0;
for (int i = 0; i < cik; i++)
for (int j = 0; j < cik; j++)
if (graphs[i][j] == 0) a++;
return a;
}
boolean way(int hm)
{
int the_last=0;

int i = 0;
int j = 0;
boolean test = false;
boolean ar2 = false;
String ats = "";
if (routes!=0)
test2(routes);
for (i = 0; i < cik; i++)
{
if (testIt(i)) { //tikrina ar yra vienetuku eiluteje
while (!test) { //eina till pirmo vienetuko
if (graphs[i][j] != 0) {
if (graphs[i][j] == 2)
{
graphs[i][j] = 1;
ar2 = true;
}
if (graphs[i][j] == 1 && !ar2)
{
the_last = i;

graphs[i][j] = -1;
graphs[j][i] = -1;
i = j - 1;
test = true;
}
ar2=false;
}
if (j < cik-1) j++;
else test = true;
}
ats=ats+the_last;
test = false;
j = 0;

}
else
{
ats= ats+i;
routes++;
if ((ats.length()==edges || ats.length()==edges) &&
ats.toCharArray()[0] == ats.toCharArray()[edges-1])
System.out.println(ats + " - Oilerio ciklas");
else if (ats.length()==edges || ats.length()==edges + 1)
System.out.println(ats + " - Oilerio kelias");
return true;
}
}
routes++;
System.out.println("");

return false;
}
boolean testIt(int i)
{
for (int jj = 0; jj <cik; jj++)
{
if (graphs[i][jj] == 1) return true;
}
return false;
}
public void test2(int xxx)
{
formatArray();
int eil = 1;
eil = xxx/(edges*2-2) + 1;
int last[][] = new int[2][xxx];
int temp = xxx;
int test = 0;
for (int i = 0; i < eil; i++)
{
ffind(temp);
last[0][test] = i1;
last[1][test] = j1;
test++;
temp = temp - test*(edges*2-2);
}
for (int i = 0; i < test; i++)
{
graphs[last[0][i]][last[1][i]] = 2;
}

}
public void ffind(int xxx)
{
int hm = 0;
for (int i =0; i < cik; i++)
for (int j = 0; j < cik; j++)
{
if (graphs[i][j] == 1 && xxx == hm)
{
i1=i; j1=j;
}
hm++;
}
}

public int nEdges()
{
int test = 0;
for (int i = 0; i < cik; i++)
for (int j = 0; j < cik; j++)
if (graphs[i][j]==1) test++;
return test/2+1;
}
}

//--------------------------------------------------------------------------------------------

package euler;

public class Programa
{
static int grafai[][];
static int i1, j1;
static int kelintas;
static int iki;
static int pabaiga;
static int kiek_marsrutu;
static int kiek_briaunu;
static int cik = 7;

public Programa()
{
grafai = new int[cik][cik];
}

public static void main(String[] args)
{
Programa a = new Programa();
a.suformuotiMasyva();
kiek_briaunu = a.kiekBriaunu();
a.indeksai();
int kiekis = a.kiek();
boolean tess;
for (int i = 0; i < 1000; i++)
tess = a.kelias(1);
}
public void suformuotiMasyva()
{
for (int i = 0; i < cik; i++)
for (int j = 0; j < cik; j++)
grafai[i][j] = 0;

grafai[0][1] = 1;
grafai[0][5] = 1;
grafai[0][3] = 1;
grafai[0][6] = 1;

grafai[1][0] = 1;
grafai[1][2] = 1;
// grafai[1][3] = 1;
// grafai[1][4] = 1;

grafai[2][1] = 1;
grafai[2][3] = 1;
grafai[2][4] = 1;
grafai[2][5] = 1;

grafai[3][0] = 1;
// grafai[3][1] = 1;
grafai[3][2] = 1;
// grafai[3][4] = 1;

grafai[4][5] = 1;
grafai[4][2] = 1;
// grafai[4][2] = 1;
// grafai[4][3] = 1;

grafai[5][0] = 1;
grafai[5][2] = 1;
grafai[5][4] = 1;
grafai[5][6] = 1;

grafai[6][0] = 1;
grafai[6][5] = 1;
// grafai[6][2] = 1;
// grafai[6][3] = 1;
}
void indeksai()
{
suformuotiMasyva();
int kiek = 0;
for (int i = 0; i < cik; i++)
for (int j = 0; j < cik; j++)
{
if (grafai[i][j] == 1) kiek++;
}
}

int kiek()
{
int a = 0;
for (int i = 0; i < cik; i++)
for (int j = 0; j < cik; j++)
if (grafai[i][j] == 0) a++;
return a;
}
boolean kelias(int kiek)
{
int paskutinis=0;

int i = 0;
int j = 0;
boolean test = false;
boolean ar2 = false;
String ats = "";
if (kiek_marsrutu!=0)
{
test2(kiek_marsrutu);
// spausdintiGrafus();

}
// spausdintiGrafus();
for (i = 0; i < cik; i++)
{
if (patikra(i)) { //tikrina ar yra vienetuku eiluteje
while (!test) { //eina iki pirmo vienetuko
if (grafai[i][j] != 0) {
if (grafai[i][j] == 2)
{
grafai[i][j] = 1;
ar2 = true;
}
if (grafai[i][j] == 1 && !ar2)
{
paskutinis = i;

grafai[i][j] = -1;
grafai[j][i] = -1;
i = j - 1;
test = true;
}
ar2=false;
}
// if (grafai[i][j] == 2) grafai[i][j]=1;
if (j < cik-1) j++;
else test = true;
}
ats=ats+paskutinis;
test = false;
j = 0;
// spausdint();

}
else
{
ats= ats+i;
kiek_marsrutu++;
if ((ats.length()==kiek_briaunu || ats.length()==kiek_briaunu)
&& ats.toCharArray()[0] == ats.toCharArray()[kiek_briaunu-1])
System.out.println(ats + " - Oilerio ciklas");
else if (ats.length()==kiek_briaunu ||
ats.length()==kiek_briaunu + 1) System.out.println(ats + " - Oilerio
kelias");
return true;
}
}
kiek_marsrutu++;
System.out.println("");
// test2(kiek_marsrutu);

return false;
}
boolean patikra(int i)
{
for (int jj = 0; jj <cik; jj++)
{
if (grafai[i][jj] == 1) return true;
}
return false;
}
public void test2(int kuris)
{
suformuotiMasyva();
int eil = 1;
eil = kuris/(kiek_briaunu*2-2) + 1;
int laikinas[][] = new int[2][kuris];
int laik = kuris;
int test = 0;
for (int i = 0; i < eil; i++)
{
surasti(laik);
laikinas[0][test] = i1;
laikinas[1][test] = j1;
test++;
laik = laik - test*(kiek_briaunu*2-2);
}
for (int i = 0; i < test; i++)
{
grafai[laikinas[0][i]][laikinas[1][i]] = 2;
}

}
public void surasti(int kuris)
{
int kiek = 0;
for (int i =0; i < cik; i++)
for (int j = 0; j < cik; j++)
{
if (grafai[i][j] == 1 && kuris == kiek)
{
i1=i; j1=j;
}
kiek++;
}
}

public void spausdintiGrafus()
{
for (int i = 0 ; i < cik; i++)
{
for (int j = 0; j < cik; j++)
System.out.print(grafai[i][j] + " ");
System.out.println("");
}

}
public int kiekBriaunu()
{
int test = 0;
for (int i = 0; i < cik; i++)
for (int j = 0; j < cik; j++)
if (grafai[i][j]==1) test++;
return test/2+1;
}
}
Mar 19 '07 #6
dk*******@gmail.com wrote:
>
package euler;

public class Programa
{
//...
public static void main(String[] args)
{
Programa a = new Programa();
a.formatArray();
//...
boolean tess;
Sorry, but this is not a C++ program.
Mar 20 '07 #7
On Mar 20, 3:32 pm, "Ralph D. Ungermann" <r...@flexis.dewrote:
dkulta...@gmail.com wrote:
package euler;
public class Programa
{
//...
public static void main(String[] args)
{
Programa a = new Programa();
a.formatArray();
//...
boolean tess;

Sorry, but this is not a C++ program.
Amazing

Mar 20 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: webposter | last post by:
Hi, I am looking for information on a data structure (and associated algorithm) to do short-circuit evaluation of boolean expressions and haven't found a single one even after googing for two...
5
by: Michael Jørgensen | last post by:
Hi there, Is there any difference between bool success = SomeFunctionReturningFalse(); success &= SomeOtherFunction(); and bool success = SomeFunctionReturningFalse();
0
by: rakesh.Mysore | last post by:
hi Currently am working on project which have graphical editor for circuit diagram which involve validation of circuit and logic flow in circuit diagram.(process diagram from left to right). ...
0
by: pranesh.nayak | last post by:
Currently am working on project which has graphical editor for circuit diagram which involve validation of circuit and logic flow in circuit diagram.(process diagram from left to right). please...
10
by: Protoman | last post by:
Hi! I'm trying to compute Euler's totient function for an extremely simple RSA program I'm writing. How, exactly, is it calculated? Thanks!
1
by: luna18 | last post by:
i like to do programming but i am not a computer student.. =) i m trying to write a program to determine a euler circuit.but end up all stuck... i tyr to take the input as graph and if it is a...
25
by: jwrweatherley | last post by:
I'm pretty new to python, but am very happy with it. As well as using it at work I've been using it to solve various puzzles on the Project Euler site - http://projecteuler.net. So far it has not...
0
by: liukaiyuan | last post by:
American Made Circuit Exercise Equipment Come look and see the circuit traning exercise equipment that is fully ajustible to fit all your work out needs. Start your own center today....
4
by: process | last post by:
I am trying to solve project euler problem 18 with brute force(I will move on to a better solution after I have done that for problem 67). http://projecteuler.net/index.php?section=problems&id=18 ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.