|
Actually the algorithm. Each roof surface is oriented and inclined in a specific angle. The array I use is the grouping of the roof surfaces to these fields. The orientations and inclinations have to be transferred to the "connectables" afterwards to calculate generated power. That's why I have to know wich element of the intConnectables belongs to wich sum in intRoofSurfaces.
|
|
|
|
|
Can you use the connectables once per roof surface or just once (across all roof surfaces)?
For now I'm guessing the latter..
And you must use all of them?
You could maybe (in pseudo code):
(!!untested!!)
bool Solve(int i)
{
if (i == numberOfConnectables + 1)
return true;
for each RoofSurface
add Connectable[i] to the RoofSurface
if (RoofSurface.Sum <= RoofSurface.Target)
{
if (Solve(i + 1))
return true
}
remove Connectable[i] from the RoofSurface
endfor
return false
}
Just an idea, I'll go test it in a moment
|
|
|
|
|
Just once across all roof surfaces. In the end I need to know if the "puzzle" can be solved and -if so- wich connectable belongs to wich roof surface.
The array intRoofSurfaces contains the targets. The most important thing I need to know is if there is a possibility to divide the elements of intConnectables[] into n groups where n is the number of elements in intRoofSurfaces. If it proves to be possible, I need to know for every element in intConnectables[] to wich element of intRoofSurfaces[] it is connected.
I know, I'm being a little picky right now, but I really need to get it before I can code the next parts of my program.
The following is just informative, so don't take it in consideration when posting your ideas just yet... Therefore I'll put it in a smaller font.
I have a set with a whole bunch of combinations (arrays intConnectables[]). Every combination will be checked. A few steps later, the roof surfaces are ungrouped and I'll have to do a reversed algorithm. More or less, because a connetable will now be usable across roof surfaces.
e.g.
The grouped roof surface has to contain 28 modules and it exists of 3 roof surfaces: 15, 7 and 6 modules. There are 4 connactables assigned, 9, 8, 6 and 5 modules.
intConnectables[] = {9, 8, 6, 5}
intSeperateRoofSurfaces[] = {15, 7, 6}
Then I would have to get a result like this:
9 + 6 = 15 | 7 [from 8] = 7 | 5 + 1 [from 8] = 6
So the connectable of 8 has been split into 7 and 1.
Just informative...
|
|
|
|
|
Ok can you verify this please?
Connectables = { 24, 22, 20, 17, 12, 11, 10, 7, 6 }
RoofSurfaces = { 43, 38, 37, 11 }
Answer = yes, { 0, 1, 2, 2, 0, 3, 1, 0, 1}
|
|
|
|
|
Works like a charm! Thanks
|
|
|
|
|
Tested, works (for the problem as I understood it, anyway):
static class Solver
{
static int[] RoofSurfaces, Connectables, Sums, AssignedTo;
public static int[] Solve(int[] connectables, int[] roofSurfaces)
{
RoofSurfaces = roofSurfaces;
Connectables = connectables;
Sums = new int[roofSurfaces.Length];
AssignedTo = new int[connectables.Length];
for (int i = 0; i < AssignedTo.Length; i++)
AssignedTo[i] = -1;
if (solve(0))
return AssignedTo;
return null;
}
static bool solve(int i)
{
if (i == Connectables.Length)
return true;
for (int k = 0; k < Sums.Length; k++)
{
Sums[k] += Connectables[i];
AssignedTo[i] = k;
if (Sums[k] <= RoofSurfaces[k])
{
if (solve(i + 1))
return true;
}
Sums[k] -= Connectables[i];
AssignedTo[i] = -1;
}
return false;
}
}
If there is a solution, it returns an array with the number of the RoofSurface that each Connectable is in, otherwise it returns null.
edit: it may not be the coding style you like etc etc, I'm not trying to set a good example here, I just made this in a couple of minutes to Just Work without looking at the style too closely.
The -1's were just useful for debugging - you don't actually need them (the variable i already determines which entries are valid)
modified on Wednesday, April 28, 2010 11:03 AM
|
|
|
|
|
I don't mind the coding style, mine isn't perfect as well. But at least I have a good idea of how to solve this thing...
Big thanks!
|
|
|
|
|
You're welcome
|
|
|
|
|
I fail to see any logic between the two arrays.
If the arrays are small you could use the index as number and the value as groupnumber. Better would be to have a class with two integers and put that in an array somehow.
No matter how you do it, you'll have to define some logic between the numbers and the group there in.
V.
|
|
|
|
|
i fill combobox through datasource but at form load i have to show "None" default value of combobox. how i do it??
|
|
|
|
|
try setting it's Text property. Being bound you can not add Items programatically but the
Text property should work.
|
|
|
|
|
Add a "None" item to the collection before you bind it to the control?
modified on Wednesday, April 28, 2010 12:00 PM
|
|
|
|
|
items collection can not be modified when the datasource property is set...
|
|
|
|
|
not to the comboboxitems.
Add "None" to the dataset or whatever underlying collection the combobox is bound to.
|
|
|
|
|
Yes you can:
public bool AddItemToComboDataSource(ref ComboBox box, string displaymember_value, string valuemember_value)
{
bool succes = false;
try
{
DataView view = (DataView)box.DataSource;
DataRow row = view.Table.Rows[0];
row[0] = displaymember_value;
row[1] = valuemember_value;
view.Table.Rows.Add(row);
box.DataSource = view;
succes = true;
}
catch (Exception ex)
{
errormsg = ex.Message;
}
return succes;
}
Which is a little cheating, probably, but it works.
V.
|
|
|
|
|
hi
i want to run an dshow an application in my project and limit it to my MDI form !
can i do it? if yes how can i?
|
|
|
|
|
The answers here[^] should get you well on the way, if they work.
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
hi
im new in codeproject i would begin programming a project in c# with web devlopper
if you have any document for begining and implementing a project with a web service and IIS and SQL server
finaly
thanks you very match
your friend
ABDELHAMID
from Morrocco
|
|
|
|
|
Welcome,
but you couldn't have gotten more things wrong in your post if you'd tried really hard.
1) All bold
2) Non specific question
3) Irrelevant subject
|
|
|
|
|
thanks you i would begin programin a n tier project
|
|
|
|
|
If you are a beginner then better to buy a beginner's book or use some online learning resources or even CodeProject having lot of articles to get a basic idea.And after getting an idea try to do an application and if you face any blocking issues Let us know we'll definitely help.Try to Google it first.Best of luck.
|
|
|
|
|
You shall find some articles here and on the internet that may help you out.
But nothing beats starting by reading a book.
|
|
|
|
|
Hi
My application needs to be able to playback multiple videos simultaneously and each video needs to be synched by time. I need an API that allows me to get frames from videos rather than just using Play(), Stop() etc. I know that using Microsoft.DirectX.AudioVideoPlayback I can get a frame but its very slow. So does anyone know a high speed way of getting frames from video files or any documents I can read?
Thanx
|
|
|
|
|
How to set Audio Input to default microphone for InProc speech recognition engine in sapi5.1(C#) ?
thanks!
|
|
|
|
|
In the C++ API, you can call SetInput() [^] with null to use the default microphone. I'm hoping the .NET API works the same way.
/ravi
|
|
|
|