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 7 6841 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
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.
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
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;
}
} 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.
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: Michael Jørgensen |
last post by:
Hi there,
Is there any difference between
bool success = SomeFunctionReturningFalse();
success &= SomeOtherFunction();
and
bool success = SomeFunctionReturningFalse();
|
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).
...
|
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...
|
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!
|
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...
|
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...
|
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....
|
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
...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |