Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.2K Views
|
7 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Is there anyone out there who would like to offer some help please?

Posted 2 years ago

I have been offered a piece of Mathematica Code as a solution to a problem. I do not know how to run the code. Could someone please run it and show me the solution. The code is

teams = Table["Team" <> ToString[i], {i, 16}];
locations = Table["L" <> ToString[i], {i, 8}];
rounds = Range[15];

(* define constraints *)
team_round_pairs = Tuples[{teams, rounds}];
location_round_pairs = Tuples[{locations, rounds}];
same_location_round_pairs = Select[Subsets[location_round_pairs, {2}], Length[Intersection[#]] == 1 &];
consecutive_round_pairs = Select[Partition[team_round_pairs, 2, 1], Length[Intersection[Flatten[#]]] == 2 &];

(* define variables *)
vars = Flatten[Table[
   {team, round, location},
   {team, teams},
   {round, rounds},
   {location, locations}
], 2];

(* set up solver *)
solver = LinearOptimization[
   {1},
   Flatten[Table[
      If[team == i && location == j, 1, 0],
      {i, teams},
      {j, locations}
   ], 1],
   # == 1 & /@ vars,
   Table[0 <= x <= 1, {x, vars}],
   Flatten[Table[
      {team, location, round} \[Element] same_location_round_pairs,
      {team, teams}
   ], 1] \[Or] Flatten[Table[
      {team1, round1, location} \[Element] consecutive_round_pairs[[i]] \[And] {team2, round2, location} \[Element] consecutive_round_pairs[[i]],
      {i, Length[consecutive_round_pairs]},
      {team1, teams},
      {team2, teams},
      {location, locations},
      {round1, rounds},
      {round2, rounds},
      If[round2 == round1 + 1 && team1 != team2, True, False]
   ], 5];

(* solve and display solution *)
solution = Partition[Round[solver[[1]]], Length[locations]];
Grid[Join[{{"", "Round 1", "Round 2", "Round 3", "Round 4", "Round 5", "Round 6", "Round 7", "Round 8", "Round 9", "Round 10", "Round 11", "Round 12", "Round 13", "Round 14", "Round 15"}}, 
    Transpose[{teams, solution}]], Dividers -> All]
Attachments:
POSTED BY: John Majkut
7 Replies
Posted 2 years ago

The code was generated by ChatGPT and is supposed to solve a problem where 16 teams are playing a 15 game round robin competition on 8 locations. Every team must play on every location at least once but no more than 3 times and no team is allowed to play on the same location two games in a row

POSTED BY: John Majkut
Posted 2 years ago

I have been offered a piece of Mathematica Code as a solution to a problem

Offered by whom? ChatGPT or some other LLM?

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Can you clarify what kind of help you're asking for?

I do not know how to run the code

That might mean that you don't have a Mathematica license and so literally don't have a way to run the code on your machine.

Or it could be that you're just unfamiliar with the notebook interface and so you're not sure how to "make stuff happen".

Or it might mean that when you try to run it you're encountering something unexpected and don't know how to proceed from there.

Or...?

POSTED BY: Eric Rimbey

Presumably you know what the code is expected to do. Adding explanatory remarks will improve the chances of someone being able to repair the code appropriately, or perhaps to offer something better.

POSTED BY: Daniel Lichtblau
Posted 2 years ago

There is a missing ] somewhere following the solver = LinearOptimization[ I've tried a couple of guesses where to insert that and haven't found a fix. And there are a few backslashes that were eaten by the pasting process, but those are easy to find and replace.

POSTED BY: Bill Nelson
Posted 2 years ago

I am not a programmer or mathematician and also dont know how to use mathematica I am just looking for help

POSTED BY: John Majkut
Posted 2 years ago

Hi John,

I have not looked through all of the code, however, I did notice symbols with underscores in their name e.g. team_round_pairs. In the Wolfram Language, underscore represents Blank which is a pattern matching construct. Use names like teamRoundPairs. Try that and see if it helps.

POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard