|
Here is the question:
12-player are in a 6-day competition. The competition have 6 different games. the rule is:
1. Every player must participate all 6 games.
2. Each player can only play the same game ONCE.
3, Each player can only play with the same opponent ONCE.
The problem is my algorithm cannot scheduling all the players into the games.
Here is my code:
Public Class clsGame
Public teams As ArrayList
Public Sub New(ByVal intTeamNumber As Integer)
teams = New ArrayList
teams.Capacity = intTeamNumber
End Sub
Public Sub add(ByVal intTeam As Integer)
If Not isFull() And Not contains(intTeam) Then teams.Add(intTeam)
End Sub
Public Function isEmpty() As Boolean
If teams.Count = 0 Then Return True
Return False
End Function
Public Function isFull() As Boolean
If teams.Count = teams.Capacity Then Return True
Return False
End Function
Public Function contains(ByVal intTeam As Integer) As Boolean
If teams.Contains(intTeam) Then Return True
Return False
End Function
End Class
Public Class clsSummerCamp
Public intDays As Integer
Public teams As New Queue
Public swimming() As clsGame
Public games(,) As clsGame
Public Sub New(ByVal intNewDays As Integer, ByVal intTeams As Integer)
intDays = intNewDays
ReDim swimming(intDays)
ReDim games(intDays, 6)
For intCount As Integer = 0 To intTeams - 1
teams.Enqueue(intCount)
Next
End Sub
Public Sub schedule(ByVal t As Queue)
Dim temp As Queue = t.Clone
initiateGames()
While Not temp.Count = 0
Dim intTeamNumber As Integer = temp.Dequeue
For intDay As Integer = 0 To intDays - 1
setGames(intDay, intTeamNumber)
Next
End While
End Sub
Public Sub initiateGames()
For intGameDay As Integer = 0 To games.GetUpperBound(0) - 1
For intCount As Integer = 0 To games.GetUpperBound(1) - 1
games(intGameDay, intCount) = New clsGame(2)
Next
Next
End Sub
Public Sub setGames(ByVal intDay As Integer, ByVal intTeam As Integer)
For intCount As Integer = 0 To games.GetUpperBound(1) - 1
If games(intDay, intCount).isEmpty Then
If Not isPlayed(intCount, intTeam) Then
games(intDay, intCount).add(intTeam)
Exit For
End If
ElseIf Not games(intDay, intCount).isFull Then
If Not games(intDay, intCount).contains(intTeam) And Not isPlayed(intCount, intTeam) Then
If Not isPlayedWith(games(intDay, intCount).teams.Item(0), intTeam) Then
games(intDay, intCount).add(intTeam)
Exit For
End If
End If
End If
Next
End Sub
Public Function isPlayed(ByVal intGame As Integer, ByVal intTeam As Integer) As Boolean
For intDay As Integer = 0 To games.GetUpperBound(0) - 1
If games(intDay, intGame).contains(intTeam) Then Return True
Next
Return False
End Function
Public Function isPlayedWith(ByVal intTeam1 As Integer, ByVal intTeam2 As Integer) As Boolean
For intDay As Integer = 0 To games.GetUpperBound(0) - 1
For intCount As Integer = 0 To games.GetUpperBound(1) - 1
If games(intDay, intCount).contains(intTeam1) And games(intDay, intCount).contains(intTeam2) Then Return True
Next
Next
Return False
End Function
Public Sub printSchedule()
schedule(teams)
For int1 As Integer = 0 To games.GetUpperBound(0) - 1
Console.Write("Games: ")
For int2 As Integer = 0 To games.GetUpperBound(1) - 1
Console.Write("{0,-10}", games(int1, int2).teams.Item(0) & " vs " & games(int1, int2).teams.Item(1) & " ")
Next
Console.WriteLine()
Next
End Sub
End Class
Module modTest
Sub Main()
Dim summerCamp As New clsSummerCamp(6, 12)
summerCamp.printSchedule()
Console.Read()
End Sub
End Module
|
|
|
|
|
Hi All,
i have a project that uses a Dll file that the owners are no longer maintaining but have released the source code. i have edited all the URLS to comply with the new twitter api v1.1. my problem is, is that the responses from the server are now sent back via JSON format and no longer XML but all the parse code is parsed via XML. i have no experience in XML or JSON so i was wondering how to go by fixing this so many people who like me are needing this .dll updated would really appreciated if someone can help convert it or some guidance on how to convert it. Bellow are some of the code that needs to be converted but there is a lot more.
Private Function ParseRelationships(ByVal Xml As String) As List(Of TwitterRelationship)
Dim XmlDoc As New XmlDocument
XmlDoc.LoadXml(Xml)
Dim Relationships As New List(Of TwitterRelationship)
For Each RelationshipNode As XmlNode In XmlDoc.SelectNodes("//relationship")
Relationships.Add(New TwitterRelationship(RelationshipNode))
Next
Return Relationships
End Function
Private Function ParseLists(ByVal Xml As String, ByRef NextCursor As Int64) As List(Of TwitterList)
Dim XmlDoc As New XmlDocument
XmlDoc.LoadXml(Xml)
Dim Lists As New List(Of TwitterList)
For Each ListNode As XmlNode In XmlDoc.SelectNodes("//list")
Lists.Add(New TwitterList(ListNode))
Next
NextCursor = Convert.ToInt64(XmlDoc.SelectSingleNode("//next_cursor").InnerText)
Return Lists
End Function
|
|
|
|
|
If you're working with JSON, then JSON.NET[^] is probably the best place to start.
However, you might do better to start with a library which supports v1.1 of the API. A quick look on the Twitter libraries page[^] provides several open-source options which look like they should fit your requirements:
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you i shall look into it
|
|
|
|
|
Hi Pete, what is it that you want to do with Twitter? I have used Linqtotwitter in Visual Basic successfully. Regards henry Hugo
|
|
|
|
|
Hi there,
This is a bit of a complicated question.
I'm building a Windows Form Application. In the database, there are paths to certain external resources. All of these resources are in a pool. In the past, just the absolute paths to the resources were saved, but now, I want to implement the app.config file to define a path to a "resource pool" and save the data as absolute paths from this pool.
All of the resources are on the same server, so I would like to get UNC paths. Problem is: the current paths are stored as normal Windows paths using a mapped network drive.
For example: the resource pool is located at \\fileserver\resx\resources . There's a mappad drive, X: , referring to \\fileserver\resx . In the current database, paths are stored as \\fileserver\resx\resources\img\img1.jpg or as X:\resources\img\img1.jpg (both notations are used randomly across the records).
What I want to achieve is the following. Let's say I've got the following URLs:
Dim strBase as String = "\\fileserver\resx\resources"
Dim strUrlA as String = "X:\resources\img\img1.jpg"
Dim strUrlB as String = "\\fileserver\resx\resources\img\img1.jpg"
Dim strUrlC as String = "Y:\tracks\track1.mp3"
Dim strUrlD as String = "\\fileserver\audio\tracks\track1.mp3"
Is there a method to convert those files as being relative to the pool? In this case, both strUrlA and strUrlB would be converted to img\img1.jpg and both strUrlC and strUrlD would be converted to ..\..\audio\tracks\track1.mp3 .
What would be a good way to handle this?
Thanks in advance!
Cheers!
|
|
|
|
|
You'll need to start by converting the mapped drive paths to UNC paths. If you have a fixed mapping scheme, you could do that manually. Otherwise, you'll need to P/Invoke WNetGetUniversalName[^] to convert the local paths to UNC paths.
Once you have consistent paths, you can use the Uri class[^] to parse the paths, and the MakeRelativeUri method[^] to get the relative paths.
Dim basePath As New Uri("\\fileserver\resx\resources\")
Dim pathA As New Uri("\\fileserver\resx\resources\img\img1.jpg")
Dim pathARelative As String = basePath.MakeRelativeUri(pathA).ToString()
Dim pathB As New Uri("\\fileserver\audio\tracks\track1.mp3")
Dim pathBRelative As String = basePath.MakeRelativeUri(pathB).ToString()
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi Richard,
First of all, thanks for your advice. Just two more questions though:
- Do I manually need to replace the forward slashes by back slashes in a Windows environment or does Windows do this for me (Win7/Win8)
- Is WNetGetUniversalName a plug-in I need or just a class I can create (by using the code on the page and just copying and pastng it into a new class?
Cheers!
|
|
|
|
|
Windows should be able to handle paths with forward-slashes. You can also use the Uri class to get back to the absolute path to the file:
Dim basePath As New Uri("\\fileserver\resx\resources\")
Dim pathBAbsolute As String = New Uri(basePath, "../../audio/tracks/track1.mp3").LocalPath
WNetGetUniversalName is a Windows API which isn't exposed through a .NET class. To access it, you have to use a technique called P/Invoke (short for "Platform Invoke"). The code samples on pinvoke.net are usually good enough to get you started.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
hi, i can't view the attached photo because of security of my computer. But here's the codes that i'm using for combining the 3 cell into 1 cell.
]
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=192.168.xx.xx;Initial Catalog=information;Persist Security Info=True;User ID=me;Password=cute"
cmd.Connection = con
con.Open()
Dim qr As String = "SELECT (Firstname + MI + Lastname) as Full_Name FROM directory1"
Dim ds As New DataSet
Dim da As New SqlDataAdapter(qr, con)
da.Fill(ds, "directory1")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "directory1"
con.Close()
|
|
|
|
|
|
Hello !
I have groupbox with several controls inside.
When a condition is true , I want to prevent users clicking on the controls inside groupbox , but without disabling groupbox or controls.
How can I do that ?
|
|
|
|
|
This is counter-intuitive in the Windows interface application. If a control, like a button, is not greyed out people expect it to be clickable. This is referred to as a "consistent user experience" across all applications running in Windows.
If by "clickable" you mean that the use clicks a button and nothing happens, you have to "unwire" the Click event handler using the RemoveHandler[^] statement. This also means you have to rewire up the handler when you need it to work again, using AddHandler[^].
|
|
|
|
|
Thank you !
The problem is that all these controls are bound to a database .I want that users can see all the data inside these controls ( TextBox , Combobox , ...etc ) all the time. When a condition become true , I want that user can still continue to see the data inside these controls ( If they become grey , is difficult to do that ) but I want to prevent them from modifying the data in these controls.
For me is not a problem that this is a deviation from default behavior in all windows application.
Is possible to prevent user modifying data in the controls inside groupbox without making them grey ?
Thank you !
|
|
|
|
|
Make two copies of the GroupBox. One, is your "readonly" version, where you have TextBoxes for all of your fields. Set the ReadOnly property on those to True. The other is your "edit" copy where you have your normal controls. When the form is in "readonly" mode, hide the "edit" groupbox and show only the "readonly" groupbox.
|
|
|
|
|
Hello !
Ok , but the groupbox have a lot of controls (52 ) and if I duplicate all these , do you think is a good solution ?And The readonly property will make the control grey
I read somewhere about
IMessageFilter .
Can be this a solution for my case ?
And if yes , can you help me with an idea how to implement ?
Thank you !
modified 27-Apr-14 9:53am.
|
|
|
|
|
IMessagFilter isn't going to help you because it filters messages before your application's message pump dispatches messages into events in your code.
You could do it, but it would take a ton of work to get it to filter out keyboard and mouse messages only on some controls and not others. I'm talking far more than just duplicating controls into two differing groups.
By the way, 52 controls to display data seems a bit excessive, but hey, I don't know your app.
modified 1-May-14 11:17am.
|
|
|
|
|
Ok, I'm thinking for another way :
It is possible to make a panel transparent ? , so when the condition is true I can put the panel over my controls , and the user can see the data in the controls , but can't click ?
But to do this I need a transparent panel ???
|
|
|
|
|
It's possible, but Transparent doesn't work the way you think it does in Windows Forms.
A Transparent Backcolor only tells the control to take on the Background properties of the container than holds it. You cannot see other controls through a "transparent" Panel, or any other control in Windows Forms.
You'd have to make your own custom control to do it. Google for "Transparent Panel VB.NET".
|
|
|
|
|
Hello !
I have implemented Imessage filter to resolve my case.
This is the class :
Imports System.Windows.Forms
Public Delegate Sub InsideDelegate(ByRef value As Boolean)
Public Class MyMessageFilter
Implements IMessageFilter
Public Event Inside As InsideDelegate
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_LBUTTONUP As Integer = &H202
Public Function PreFilterMessage(ByRef m As Message) As Boolean Implements IMessageFilter.PreFilterMessage
Return OnInside()
End Function
Private Function OnInside() As Boolean
Dim _inside As Boolean = True
If InsideEvent IsNot Nothing Then
InsideEvent(_inside)
End If
Return _inside
End Function
End Class
This is the code on my form :
Dim filter As New MyMessageFilter()
Private Flag1 As Boolean = True
Private Sub filter_Inside(ByRef value As Boolean)
value = If((Groupbox1.ClientRectangle.Contains(Groupbox1.PointToClient(Control.MousePosition)) AndAlso Flag1), True, False)
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles Me.Load
AddHandler filter.Inside, AddressOf filter_Inside
Application.AddMessageFilter(filter)
End Sub
This works , but I have some problems :
1)
I have a main form with menu and several other forms. On one of this forms ( not main) I have implemented Imessage filter. But when I close this form , I get an error on this sub :
Private Sub filter_Inside(ByRef value As Boolean)
value = If((GroupBox1.ClientRectangle.Contains(GroupBox1.PointToClient(Control.MousePosition)) AndAlso Flag1), True, False)
End Sub
: An unhandled exception of type 'System.ObjectDisposedException' occurred in System.Windows.Forms.dll
Additional information: Cannot access a disposed object.
What can I do ?
2)
I have noticed a problem in a groupbox that have bound controls.
I have a button that delete records from this form.And if the last record is deleted , I set the flag1 for the GoupBox1 to true ( so not clickable).
but on runtime , when I delete the last record , the bound textboxes should become empty. But they become empty only when I move the mouse outside the groupbox1. ( I didn't have this problem before implementing Imessage filter for this groupcontrol )
What can I do ?
Thank you !
|
|
|
|
|
I told you this wasn't going to work for you without a LOT of work. You're using a sledge hammer to kill a fly.
1) The reason it's telling you the object is disposed is because the filter is still running, but the GroupBox doesn't exist any more. If you Close and Dispose the form, the GroupBox is destroyed, so there's nothing to get a ClientRectangle from!
2) If you called Delete, you TAGGED the record in your DataTable for delete. It does NOT get deleted until you or something else calls AcceptChanges on either the DataRow you deleted or on the DataTable that contains it.
|
|
|
|
|
Thank you !
1) Is possible to use Application.RemoveMessageFilter(filter) on the form's closing method ? Can this resolve the problem ?
2) I call all the methods needed because before implementing Imessage filter everything was worked. But after implementing the imessagefilter on the Groupbox that contain the bound controls , I have this problem. After pressing the delete button , I have a Messagebox to confirm the deletion , and after pressing "Yes" , the mouse pointer remain inside the groupbox . Only If I remove the mouse outside the controls become empty. What can I do ?
Thank you !
|
|
|
|
|
hi everyone,
i need your help!
i successfully merge 3 columns to one column in datagridview but the problem is, there is no spaces between the merged data. And also how to separate data by "/"? My data base is sql and i'm using vb.net2008
thank you in advance
<code>
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=192.168.xx.xx;Initial Catalog=directory1;Persist Security Info=True;User ID=me;Password=cute"
cmd.Connection = con
con.Open()
Dim qr As String = "SELECT names,(dept + div + pos) as dept_div_pos, tel, local FROM directory1"
Dim ds As New DataSet
Dim da As New SqlDataAdapter(qr, con)
da.Fill(ds, "directory1")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "directory1"
con.Close()
</code>
modified 30-Apr-14 3:06am.
|
|
|
|
|
separate by space
dept + ' ' + div + ' ' + pos
separate by /
dept + '/' + div + '/' + pos
|
|
|
|
|