Author Topic: Energy Effeciency Programming Challenge (CANCELED)  (Read 10183 times)

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Energy Effeciency Programming Challenge (CANCELED)
« on: March 14, 2012, 11:13:52 am »
EDIT3: CANCELED due to a degenerate, almost naivly greedy, linear time (O(energy goal + num planets)) algorithm being found. This basically makes this problem no fun at all.
EDIT4: The revised version is NOT coming, due it being shown that the general form of this problem is NP-hard.
Funny, seeing that sicking with the current sets of reactor definitions makes this problem linearly solvable.

Thanks to the recent energy management discussion, I came up with an idea for a programming challenge.
EDIT: Feel free to PM me submissions, but you may want to wait until I get some sample input and output generated first so you can test it.
Also, it will be a while until I can actually test it, as now I need to write the test data and my own "judging" implementation and verifier.

Write an algorithm that given a certain power goal and maximum number of planets to use, will give the best configuration of powered on energy reactors that will minimize per-second resources cost but still at least meets the energy goal. You are free to place as many reactors as you want on as many planets (up to the max) as you want, as long as you minimize per second cost.
Best is defined as the configuration that consumes the lease resources per second. If multiple configurations have the same resources per second cost, then the best is the configuration that costs the least amount to construct all reactors. If multiple configurations are tied in both ways, then the configuration that minimizes number of planets used will be that best. And finally, if all three tie-breakers are tied, then the configuration using the least number of reactors is the best. If all of the above are the same, then the configurations can be considered equal, and if assured to be the best overall, will all be considered "right" optimal answers.

Also, a separate challenge for the above problem but also accepting a list of already constructed energy reactors and working off of those. In this case, you cannot "build" more reactors, you can only return a subset of the reactors given to turn on.
Best is defined the same way, except that instead of measuring cost and number of reactors built, instead it will measure cost and number of reactors turned on in the final configuration.

Just as a note, the naive greedy algorithm (always go for the most efficient reactor first) will not always give the best results (though in most cases, it will give pretty good results). Preferably something less than exponential running time (aka, not take a brute force approach). Keep in mind that LARGE amounts of pruning of the state space can be done due to tell early that some sub-configuration will lead to unoptimal results.

Recognition will go towards those who can give an algorithm with the best worst case asymptotic running time (aka, O(n) time, or in this case O(e, n)). Also, recognition will go to those who have the best average O(n) time given "normal" sets of input that you would expect in a real game. (Some analysis showing why your code runs tends to run better asymptotically in this case would be appreciated)
Special mention will go to those with "clever" or "funny" solutions.
I am avoiding wall-clock time testing due to how difficult it is to compare runtimes fairly across different languages and machines.
Separate recognition for each variation of the challenge. You may submit the same code twice for each challenge, with taking "null" or an empty array or whatever indicating that there is no set of reactors is must work with and thus.

EDIT2: If someone can prove that with the stats used for reactors and the way poor efficiency is handled in the current version of AI war leads to a simple greedy algorithm being optimal, then I will amend the requirements to have the program take an arbitrary set of reactor stat definitions. In fact, I might do that anyways.
This problem is VERY similar to the "change problem". For some sets of denomination/reactor value greedy solutions may work, but in the general case, the greedy solution is not guaranteed to work.
« Last Edit: March 15, 2012, 02:03:32 pm by techsy730 »

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Energy Effeciency Programming Challenge
« Reply #1 on: March 14, 2012, 11:17:40 am »
FYI, it's not much of a challenge given required energy e and a set of (cost,output) pairs.  There's only one wrinkle beyond the "pick the most efficient": check the ones with a lower efficiency but lower cost, if there's one without output >= remaining needed e, pick the lowest cost of those.
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Energy Effeciency Programming Challenge
« Reply #2 on: March 14, 2012, 11:38:31 am »
Accepted languages: C, C++, C#, Java, Scala, Python (let me know if there is a language you are itching to use that is not on this list)
You may use any of the standard libraries included with the language, but no 3rd party libraries. (With an exception for pthreads for multi-threading in C and C++)
Your solution may be single or multi-threaded. Keep in mind though that it is tricky to measure asymptotic performance of multi-threaded approaches.

Language specific notes:
C:
Avoid compiler specific extensions and OS specific functionality. The build will be tested against the latest stable build of GCC (4.6.3 at the time of this writing). OS it will be run on is undefined. You may use ANSI C, ISO C, C99 C, or C11 C. As noted, pthreads is allowed.

C++:
Avoid compiler specific extensions and OS specific functionality. The build will be tested against the latest stable build of GPP (4.6.3 at the time of this writing). OS it will be run on is undefined. You may use the original ISO C++ ISO/IEC 14882:1998 (sometimes known as C++98), ISO/IEC 14882:2003 (sometimes known as C++03), ISO/IEC TR 19768:2007 (sometimes known as C++TR1), and ISO/IEC 14882:2011 (sometimes known as C++11, and went by C++0X before final publication)
(In short, C++98, C++03, C++TR1, and C++11)
The TR1 libraries are allowed so long as you use only the parts defined in the of the ISO/IEC TR 19768:2007 (C++TR1) standard (though if C++11 adds anything to the TR1 namespace, you may use that as well if targeting C++11). Though if you are using the TR1 libraries, you might as well use C++11, as it incorporates most of the stuff TR1 offered. As noted, pthreads is allowed.

Java:
Avoid implementation specific extensions or packages and OS specific functionality. The code submitted must NOT contain native methods or native constructors. The build will be tested against the latest stable Oracle (formally Sun) JDK (1.7.0_03). OS it will be run on is undefined. You may use any Java standard (for both source and library classes) from Java 1.2 to Java 1.7 (inclusive)

Python:
Avoid implementation specific extensions or classes and OS specific functionality. The code submitted must NOT use any sort of foreign function interface. The build will be tested against the latest stable CPython (the "standard" Python) version (at the time of this writing, for Python 2 submissions, 2.7.2, for Python 3 submissions, 3.2.2). OS it will be run on is undefined. You may use the Python 2 standard or the Python 3 standard.

EDIT: Oops, forgot the C# section

C#:
Avoid compiler specific extensions and OS specific functionality. The code submitted must NOT use any sort of foreign function interface. Classes, methods, and codeblocks defined as unsafe are allowed, though beware of the pitfalls that can lead to (especially with portability). The build will be tested against the latest stable build of Mono (2.10.8 at the time of this writing). OS it will be run on is undefined. You may use any C# standard from C# 1 to C# 4 (inclusive)
« Last Edit: March 14, 2012, 11:48:57 am by techsy730 »

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Energy Effeciency Programming Challenge
« Reply #3 on: March 14, 2012, 11:39:53 am »
I will need some help with judging (for the runtime analysis) and possibly for help with languages I am not familiar with (like C# and Python)

Also, I need some help with sample input and output, and input and output to judge.

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Energy Effeciency Programming Challenge
« Reply #4 on: March 14, 2012, 11:51:20 am »
Output should be written to standard out. (Output written to standard error will be ignored)

Input will be a file called in.csv with the following format
First line, energy requirement. Range can be [1, 2^63 ? 1] (The range of positive longs in Java and C#, and long long or int64_t in most C and C++ compilers). End of this field is signaled by a new line (or possibly a new-line + carriage-return)
Second line, maximum number of planets, can be [1, (2^31) / 2] (About half the range of positive ints in Java and C#, and long or int32_t in most C and C++ compilers (though in 64-bit compilers, so is int, but its safer just to use long)) End of this field is signaled by a new line (or possibly a new-line + carriage-return)
If the input is for the extended variation of the problem,
The third line, if present, the energy reactors that can be used. First number is the total number of reactors (call it n). Range can be [0, (2^31) / 2]. Following that will be a comma, and then n pairs of numbers (so 2*n numbers in total). Each pair will be separated by a comma, and each number within the pair will be separated by a comma. The i'th pair of numbers will represent reactor i. The first number of pair i will be the planet of the reactor (range of [0, maximum number of planets - 1], with 0 representing the first planet). The second number of pair i will be the mark of the reactor (range of [1,3])
So in total, there will be 2*n + 1 numbers on line 3. End of this field is signaled by a new line (or possibly a new-line + carriage-return)

Output format:
If it is not possible to meet the energy demand given the restraints of the input, then write out "no solution" (without the quotes) to the output. (Case insensitive check will be used)
Otherwise, the energy reactors that will be used (constructed and turned on). First number is the total number of used reactors (call it n). Range can be [0, (2^31) / 2]. Following that will be a comma, and then n pairs of numbers (so 2*n numbers in total). Each pair will be separated by a comma, and each number within the pair will be separated by a comma. The i'th pair of numbers will represent reactor i. The first number of pair i will be the planet of the reactor (range of [0, maximum number of planets - 1], with 0 representing the first planet). The second number of pair i will be the mark of the reactor (range of [1,3]). So in total, there will be 2*n + 1 numbers.
End of output is signaled by a new line.

Notes about the answers.
Isomorphism will be considered. Aka, a Mk. II and Mk. III reactor on planet 1 and a 2 Mk. II reactors on planet 2 will be considered the same configuration as 2 Mk. II reactors on planet 1 and a Mk. II and Mk. III reactor on planet 2.
Even if the solution is not isomorphic to the known "optimal" configuration, it will be tested to see if it ties with the "optimal" configuration given the definition of "best" configuration given above.
« Last Edit: March 14, 2012, 12:15:36 pm by techsy730 »

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Energy Effeciency Programming Challenge
« Reply #5 on: March 14, 2012, 11:59:23 am »
FYI, it's not much of a challenge given required energy e and a set of (cost,output) pairs.  There's only one wrinkle beyond the "pick the most efficient": check the ones with a lower efficiency but lower cost, if there's one without output >= remaining needed e, pick the lowest cost of those.

Yea, its an easy problem to simply solve, but I am looking for the "best" solution. The solution with the best asyntopic run time, the solutions that can prune the largest amount of the state space earlier on, and the ones that can scale to trillions of requested energy and thousands of maximum planets.

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Energy Effeciency Programming Challenge
« Reply #6 on: March 14, 2012, 12:05:40 pm »
Yea, its an easy problem to simply solve, but I am looking for the "best" solution. The solution with the best asyntopic run time, the solutions that can prune the largest amount of the state space earlier on, and the ones that can scale to trillions of requested energy and thousands of maximum planets.
Very well, commence Operation Sledgehammer Ant ;)
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Volatar

  • Hero Member Mark III
  • *****
  • Posts: 1,055
  • Patient as a rock
Re: Energy Effeciency Programming Challenge
« Reply #7 on: March 14, 2012, 12:06:49 pm »
Yea, its an easy problem to simply solve, but I am looking for the "best" solution. The solution with the best asyntopic run time, the solutions that can prune the largest amount of the state space earlier on, and the ones that can scale to trillions of requested energy and thousands of maximum planets.

I have one simple question: Why?

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Energy Effeciency Programming Challenge
« Reply #8 on: March 14, 2012, 12:16:35 pm »
Yea, its an easy problem to simply solve, but I am looking for the "best" solution. The solution with the best asyntopic run time, the solutions that can prune the largest amount of the state space earlier on, and the ones that can scale to trillions of requested energy and thousands of maximum planets.

I have one simple question: Why?

For SCIENCE!

Or rather because I thought it would be a fun activity for the more programmer inclined of us.  :D

Now that I realize how silly this is, feel free to move this to the off-topic board now. ;)
« Last Edit: March 14, 2012, 12:19:25 pm by techsy730 »

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Energy Effeciency Programming Challenge
« Reply #9 on: March 14, 2012, 12:19:03 pm »
Two final pieces of information I need.
One, what is the base cost, resource drain, and energy production for each of the 3 marks of reactors?
Two, what is the exact method used to determine "poor efficiency" production, including >2 reactors of the same mark on one planet, and minimum energy production (if any)?

Once, I have all the info together, I will consolidate it into the first post better.

Offline zoutzakje

  • Hero Member Mark III
  • *****
  • Posts: 1,052
  • Crosshatch Conqueror
Re: Energy Effeciency Programming Challenge
« Reply #10 on: March 14, 2012, 01:34:32 pm »
I do not know about mk I, but minimum energy of mk II is 4000 and minimum of mk III is 8000 (so I suppose it's 500 for mk I). Cost wise I believe stacking up mk II reactors is more efficient than stacking up mk III.
If that's of any help to you.

Offline Minotaar

  • Sr. Member
  • ****
  • Posts: 272
Re: Energy Effeciency Programming Challenge
« Reply #11 on: March 14, 2012, 02:30:20 pm »
Two final pieces of information I need.
One, what is the base cost, resource drain, and energy production for each of the 3 marks of reactors?
Two, what is the exact method used to determine "poor efficiency" production, including >2 reactors of the same mark on one planet, and minimum energy production (if any)?

Once, I have all the info together, I will consolidate it into the first post better.
Here you go:
MK1: build cost 1k/1.5k, drain -5/-5. The Nth reactor of this mark on a planet produces max(5000*(0.8^(N-1)),500) energy: 1 -> 5k; 2 ->4k; .. 12+ -> 0.5k
MK2: build cost 2.6k/7k, drain -15/-15. The Nth reactor of this mark on a planet produces max(40000*(0.6^(N-1)),4000) energy: 1 -> 40k; 2 ->24k; .. 6+ -> 4k
MK3: build cost 7.8k/21k, drain -40/-40. The Nth reactor of this mark on a planet produces max(80000*(0.2^(N-1)),8000) energy: 1 -> 80k; 2 ->16k; 3+ -> 8k.

Offline TechSY730

  • Core Member Mark V
  • *****
  • Posts: 4,570
Re: Energy Effeciency Programming Challenge
« Reply #12 on: March 14, 2012, 02:34:32 pm »
Two final pieces of information I need.
One, what is the base cost, resource drain, and energy production for each of the 3 marks of reactors?
Two, what is the exact method used to determine "poor efficiency" production, including >2 reactors of the same mark on one planet, and minimum energy production (if any)?

Once, I have all the info together, I will consolidate it into the first post better.
Here you go:
MK1: build cost 1k/1.5k, drain -5/-5. The Nth reactor of this mark on a planet produces max(5000*(0.8^(N-1)),500) energy: 1 -> 5k; 2 ->4k; .. 12+ -> 0.5k
MK2: build cost 2.6k/7k, drain -15/-15. The Nth reactor of this mark on a planet produces max(40000*(0.6^(N-1)),4000) energy: 1 -> 40k; 2 ->24k; .. 6+ -> 4k
MK3: build cost 7.8k/21k, drain -40/-40. The Nth reactor of this mark on a planet produces max(80000*(0.2^(N-1)),8000) energy: 1 -> 80k; 2 ->16k; 3+ -> 8k.

Thanks, that is what I needed.

Now I am wondering if someone can prove that a greedy algorithm can be used for these values to find the "best" configuration as I have defined it above.
Mere "I think it should work" or "It makes sense that it would" and other such responses will not do. I need a mathematically sound proof before I declare this problem "trivial" to solve with these sets of stats. (It doesn't have to be in formal notation, just mathematically sound)

I know for certain that in the general case (arbitrary stats for the mark levels), the greedy algorithm will not work.

Offline Eternaly_Lost

  • Sr. Member
  • ****
  • Posts: 336
Re: Energy Effeciency Programming Challenge
« Reply #13 on: March 14, 2012, 03:35:49 pm »
Two final pieces of information I need.
One, what is the base cost, resource drain, and energy production for each of the 3 marks of reactors?
Two, what is the exact method used to determine "poor efficiency" production, including >2 reactors of the same mark on one planet, and minimum energy production (if any)?

Once, I have all the info together, I will consolidate it into the first post better.
Here you go:
MK1: build cost 1k/1.5k, drain -5/-5. The Nth reactor of this mark on a planet produces max(5000*(0.8^(N-1)),500) energy: 1 -> 5k; 2 ->4k; .. 12+ -> 0.5k
MK2: build cost 2.6k/7k, drain -15/-15. The Nth reactor of this mark on a planet produces max(40000*(0.6^(N-1)),4000) energy: 1 -> 40k; 2 ->24k; .. 6+ -> 4k
MK3: build cost 7.8k/21k, drain -40/-40. The Nth reactor of this mark on a planet produces max(80000*(0.2^(N-1)),8000) energy: 1 -> 80k; 2 ->16k; 3+ -> 8k.

That is missing one part of infomation. The N only counts is only after N = number of homeworlds. So if you have 2 homeworlds Mk1 goes like this : 1-> 5k, 2->5k, 3->4k; ... 13+ ->0.5k.

Offline _K_

  • Full Member Mark III
  • ***
  • Posts: 219
Re: Energy Effeciency Programming Challenge
« Reply #14 on: March 14, 2012, 03:48:35 pm »
Alright, i dont know what your "greedy" algorithm exactly is, but here is a thing that should be noted:

2 MKI generators are cheaper than 1 MKII, so if you need 10k or less energy, its more cost efficient to turn on 2 MK1's.

Oh, also the cases when you have so much drain that you have to use the low-efficiecy generators might get it a little more complicated.