Are there Scala examples?

182 views
Skip to first unread message

RuthAnn Haefli

unread,
Dec 3, 2021, 11:09:16 AM12/3/21
to OptaPlanner development
Hello OptaPlanner Team,

 Do you have any Scala examples? 

I am new to OptaPlanner and am having trouble with the OptaPlanner and OptaPy installations.  I would like to run this in either python or scala (on Azure Databricks).  I can install the java package on databricks but cannot run the examples (as they are in java).  I've been trying to convert a java example to scala but am having trouble.  (I cannot use the Quark.io method as it doesn't work for the project I am working on.) 

Issues I am facing:
  • OptaPlanner Install on Intellij: I install OptaPlanner as specified in the User Guide, but get the following error: 
    • java: error: invalid source release: 17
    • Module optaplanner-examples SDK 1.8 is not compatible with the source version 17.
    • Upgrade Module SDK in project settings to 17 or higher. Open project settings.
  • Converting to Scala: I am able to install the OptaPlanner java package in Azure Databricks.  However, I having trouble converting the example timetableschooling example in scala - specifically with the constraints as discussed here: https://groups.google.com/g/optaplanner-dev/c/bJGUbS-5Fdk/m/6_SoFBYQAgAJ.  After reading this discussing I am still having trouble converting this code as needed.
I greatly appreciate your time.

Best,
RuthAnn
 

Christopher Chianelli

unread,
Dec 3, 2021, 11:55:28 AM12/3/21
to OptaPlanner development
In regards to OptaPy, what is the full log when installing using `pip`? Is `JAVA_HOME` set properly and a C compiler tool chain installed (https://jpype.readthedocs.io/en/latest/install.html#if-it-fails)?

In regards to OptaPlanner install on Eclipse, it look like a classpath issue. Is all of OptaPlanner dependencies on the classpath?

In regards to OptaPlanner install on Intellij, you need to modify your module settings; click "Open project settings".

RuthAnn Haefli

unread,
Dec 3, 2021, 2:04:13 PM12/3/21
to OptaPlanner development
Thank you for your quick response.



OptaPy Install error output:
C:\WINDOWS\system32>pip install OptaPy
Collecting OptaPy
  Using cached optapy-8.11.0a2-py3-none-any.whl (17.8 MB)
Collecting JPype1
  Using cached JPype1-1.3.0.tar.gz (820 kB)
Using legacy 'setup.py install' for JPype1, since package 'wheel' is not installed.
Installing collected packages: JPype1, OptaPy
    Running setup.py install for JPype1 ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\RuthAnn Haefli\AppData\Local\Programs\Python\Python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\RuthAnn Haefli\\AppData\\Local\\Temp\\pip-install-axs5ugpy\\jpype1_cc2e16a6db3d4e6ea9cb1c6c91701b1f\\setup.py'"'"'; __file__='"'"'C:\\Users\\RuthAnn Haefli\\AppData\\Local\\Temp\\pip-install-axs5ugpy\\jpype1_cc2e16a6db3d4e6ea9cb1c6c91701b1f\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\RuthAnn Haefli\AppData\Local\Temp\pip-record-t5sylcmv\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\RuthAnn Haefli\AppData\Local\Programs\Python\Python310\Include\JPype1'
         cwd: C:\Users\RuthAnn Haefli\AppData\Local\Temp\pip-install-axs5ugpy\jpype1_cc2e16a6db3d4e6ea9cb1c6c91701b1f\
    Complete output (55 lines):
    Falling back to provided JNI headers, since your provided JAVA_HOME "C:\Program Files\Java\jdk-17.0.1\bin" does not provide jni.h
    Falling back to provided JNI headers, since your provided JAVA_HOME "C:\Program Files\Java\jdk-17.0.1\bin" does not provide jni.h
    Falling back to provided JNI headers, since your provided JAVA_HOME "C:\Program Files\Java\jdk-17.0.1\bin" does not provide jni.h
    Falling back to provided JNI headers, since your provided JAVA_HOME "C:\Program Files\Java\jdk-17.0.1\bin" does not provide jni.h
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.10
    creating build\lib.win-amd64-3.10\jpype
    copying jpype\beans.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\config.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\dbapi2.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\imports.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\nio.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\pickle.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\protocol.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\types.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_classpath.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_core.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_gui.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jarray.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jclass.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jcollection.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jcustomizer.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jexception.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jinit.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jio.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jmethod.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jobject.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jpackage.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jproxy.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jstring.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jthread.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jvmfinder.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\_pykeywords.py -> build\lib.win-amd64-3.10\jpype
    copying jpype\__init__.py -> build\lib.win-amd64-3.10\jpype
    package init file 'jpype\_pyinstaller\__init__.py' not found (or not a regular file)
    creating build\lib.win-amd64-3.10\jpype\_pyinstaller
    copying jpype\_pyinstaller\entry_points.py -> build\lib.win-amd64-3.10\jpype\_pyinstaller
    copying jpype\_pyinstaller\example.py -> build\lib.win-amd64-3.10\jpype\_pyinstaller
    copying jpype\_pyinstaller\hook-jpype.py -> build\lib.win-amd64-3.10\jpype\_pyinstaller
    copying jpype\_pyinstaller\test_jpype_pyinstaller.py -> build\lib.win-amd64-3.10\jpype\_pyinstaller
    copying jpype\_core.pyi -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jcollection.pyi -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jio.pyi -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jstring.pyi -> build\lib.win-amd64-3.10\jpype
    copying jpype\_jthread.pyi -> build\lib.win-amd64-3.10\jpype
    running build_ext
    Call build extensions
    Using Jar cache
    copying native\jars\org.jpype.jar -> build\lib.win-amd64-3.10
    Call build ext
    building '_jpype' extension
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\RuthAnn Haefli\AppData\Local\Programs\Python\Python310\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\RuthAnn Haefli\\AppData\\Local\\Temp\\pip-install-axs5ugpy\\jpype1_cc2e16a6db3d4e6ea9cb1c6c91701b1f\\setup.py'"'"'; __file__='"'"'C:\\Users\\RuthAnn Haefli\\AppData\\Local\\Temp\\pip-install-axs5ugpy\\jpype1_cc2e16a6db3d4e6ea9cb1c6c91701b1f\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\RuthAnn Haefli\AppData\Local\Temp\pip-record-t5sylcmv\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\RuthAnn Haefli\AppData\Local\Programs\Python\Python310\Include\JPype1' Check the logs for full command output.
WARNING: You are using pip version 21.2.3; however, version 21.3.1 is available.
You should consider upgrading via the 'C:\Users\RuthAnn Haefli\AppData\Local\Programs\Python\Python310\python.exe -m pip install --upgrade pip' command.

Christopher Chianelli

unread,
Dec 3, 2021, 2:18:02 PM12/3/21
to OptaPlanner development
OptaPy: Look like it is indeed the C toolchain:
    error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/

OptaPlanner on Intellij: It not in the User Guide (nor is it OptaPlanner specific); go to Project Setting > Modules, set Language Level to 17 in the "Sources" tab, set Module SDK to 17 in the "Dependencies" tab. Intellij should guide you on what need to be changed if you click on the link "Open project settings".

Geoffrey De Smet

unread,
Dec 9, 2021, 7:20:29 PM12/9/21
to optapla...@googlegroups.com

Hi,

The java hello world example is probably the best one to transform into scala:
  https://github.com/kiegroup/optaplanner-quickstarts/tree/stable/hello-world

We have scala developers that successfully use optaplanner from scala,
but it's been a while since I saw new optaplanner projects using scala.
(These days we hear a lot about kotlin, so we added a quickstarts for that.)

If you run into particular issues with converting the hello world example to scala,
let us know, we're happy to help. If you can share the code repo, that could make it easier to try for ourselves.

With kind regards,
Geoffrey De Smet

--
You received this message because you are subscribed to the Google Groups "OptaPlanner development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to optaplanner-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/optaplanner-dev/019b0588-28ea-4f76-82ae-166bf78d3711n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages