-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,63 @@ | ||
package matching | ||
|
||
import( | ||
|
||
) | ||
import () | ||
|
||
type Combination struct { | ||
Quantity int | ||
Configuration []Part | ||
Quantity int | ||
Configuration []Part | ||
} | ||
|
||
type Part struct { | ||
Group *Group | ||
CandidateAmount int | ||
Group *Group | ||
CandidateAmount int | ||
} | ||
|
||
//adds a configuration to all combinations it fitts to | ||
func addToAnyIfFitting(config []*Group, c []Combination) bool { | ||
var wasAdded bool | ||
for i := range c { | ||
if c[i].addIfFitting(config) { | ||
wasAdded = true | ||
} | ||
} | ||
return wasAdded | ||
var wasAdded bool | ||
for i := range c { | ||
if c[i].addIfFitting(config) { | ||
wasAdded = true | ||
} | ||
} | ||
return wasAdded | ||
} | ||
|
||
//adds config to the combination c if it fitts | ||
func (c *Combination) addIfFitting(config []*Group) bool { | ||
if c.isFitting(config) { | ||
//if config is a subconfiguration of c.Configuration (has less wishes, but the rest is equal) it is added, | ||
//but the function returns false, so that config is also added as a own combination | ||
c.Quantity++ | ||
if len(config) == len(c.Configuration){ | ||
return true | ||
}else { | ||
return false | ||
} | ||
} | ||
return false | ||
if c.isFitting(config) { | ||
//if config is a subconfiguration of c.Configuration (has less wishes, but the rest is equal) it is added, | ||
//but the function returns false, so that config is also added as a own combination | ||
c.Quantity++ | ||
if len(config) == len(c.Configuration) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
return false | ||
} | ||
|
||
//check if config is equal to c.Configuration (the order doesn't matter) | ||
func (c *Combination) isFitting(config []*Group) bool { | ||
var count int | ||
for i := range c.Configuration { | ||
for j := range config { | ||
if c.Configuration[i].Group.Name == config[j].Name { | ||
count++ | ||
} | ||
} | ||
} | ||
if count == len(config) { | ||
for i := range c.Configuration { | ||
for j := range config { | ||
if c.Configuration[i].Group.Name == config[j].Name { | ||
c.Configuration[i].CandidateAmount++ | ||
} | ||
} | ||
} | ||
return true | ||
}else { | ||
return false | ||
} | ||
var count int | ||
for i := range c.Configuration { | ||
for j := range config { | ||
if c.Configuration[i].Group.Name == config[j].Name { | ||
count++ | ||
} | ||
} | ||
} | ||
if count == len(config) { | ||
for i := range c.Configuration { | ||
for j := range config { | ||
if c.Configuration[i].Group.Name == config[j].Name { | ||
c.Configuration[i].CandidateAmount++ | ||
} | ||
} | ||
} | ||
return true | ||
} else { | ||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.