You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@systemds.apache.org by GitBox <gi...@apache.org> on 2021/06/08 22:35:43 UTC

[GitHub] [systemds] atefeh-asayesh opened a new pull request #1306: residency hospital matching

atefeh-asayesh opened a new pull request #1306:
URL: https://github.com/apache/systemds/pull/1306


   residencymatch.dml
   residencyMatchMain.dml
   BuiltinResidencyMatchTest.java
   Builtins.java


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r649024075



##########
File path: src/test/java/org/apache/sysds/test/functions/builtin/BuiltinResidencyMatchTest.java
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.test.functions.builtin;
+
+import org.apache.sysds.runtime.matrix.data.MatrixValue;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+public class BuiltinResidencyMatchTest extends AutomatedTestBase {
+
+
+	private final static String TEST_NAME = "residencymatch";
+	private final static String TEST_DIR = "functions/builtin/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + BuiltinResidencyMatchTest.class.getSimpleName() + "/";
+
+	private final static double eps = 0.0001;
+	private final static int rows = 3;
+	private final static int cols = 3;
+
+	@Override
+	public void setUp() {
+		addTestConfiguration(TEST_NAME,new TestConfiguration(TEST_CLASS_DIR, TEST_NAME,new String[]{"SM"}));
+	}
+	@Test
+	public void testResidencyMatchTest() {

Review comment:
       Also, please do not delete the license files. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] atefeh-asayesh commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
atefeh-asayesh commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648333055



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)

Review comment:
       Done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648264495



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)
+Capacityrows = nrow(C)
+#######################################################################################################

Review comment:
       simplify the comments please do not use unnecessary "#" and "--" as it makes it difficult to read the code.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648269528



##########
File path: src/test/scripts/functions/builtin/residencymatch.dml
##########
@@ -0,0 +1,10 @@
+# this dml file will run the  ResidencyMatchMain function in builtin functions  in scripts/builtin
+R = read($1)
+H = read($2)
+C = read($3)
+alg = $4
+if( alg == "residencymatch" )

Review comment:
       please remove this condition as you have only one algorithm to match. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] atefeh-asayesh closed pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
atefeh-asayesh closed pull request #1306:
URL: https://github.com/apache/systemds/pull/1306


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648259904



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)

Review comment:
       remove the space and make it ncol(R)




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648272882



##########
File path: src/test/java/org/apache/sysds/test/functions/builtin/BuiltinResidencyMatchTest.java
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.test.functions.builtin;
+
+import org.apache.sysds.runtime.matrix.data.MatrixValue;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+public class BuiltinResidencyMatchTest extends AutomatedTestBase {
+
+
+	private final static String TEST_NAME = "residencymatch";
+	private final static String TEST_DIR = "functions/builtin/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + BuiltinResidencyMatchTest.class.getSimpleName() + "/";
+
+	private final static double eps = 0.0001;
+	private final static int rows = 3;
+	private final static int cols = 3;
+
+	@Override
+	public void setUp() {
+		addTestConfiguration(TEST_NAME,new TestConfiguration(TEST_CLASS_DIR, TEST_NAME,new String[]{"SM"}));
+	}
+	@Test
+	public void testResidencyMatchTest() {

Review comment:
       Please add more tests with different input matrices as we have done in stable marriage test. Also, add tests for single node and spark execution contexts. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648258529



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")

Review comment:
       in DML we follow two-space indentation. Please indent this code block.

##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION

Review comment:
       Please explain this TODO




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] atefeh-asayesh commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
atefeh-asayesh commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648575844



##########
File path: src/test/java/org/apache/sysds/test/functions/builtin/BuiltinResidencyMatchTest.java
##########
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysds.test.functions.builtin;
+
+import org.apache.sysds.runtime.matrix.data.MatrixValue;
+import org.apache.sysds.test.AutomatedTestBase;
+import org.apache.sysds.test.TestConfiguration;
+import org.apache.sysds.test.TestUtils;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+public class BuiltinResidencyMatchTest extends AutomatedTestBase {
+
+
+	private final static String TEST_NAME = "residencymatch";
+	private final static String TEST_DIR = "functions/builtin/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + BuiltinResidencyMatchTest.class.getSimpleName() + "/";
+
+	private final static double eps = 0.0001;
+	private final static int rows = 3;
+	private final static int cols = 3;
+
+	@Override
+	public void setUp() {
+		addTestConfiguration(TEST_NAME,new TestConfiguration(TEST_CLASS_DIR, TEST_NAME,new String[]{"SM"}));
+	}
+	@Test
+	public void testResidencyMatchTest() {

Review comment:
       done

##########
File path: src/test/scripts/functions/builtin/residencymatch.dml
##########
@@ -0,0 +1,10 @@
+# this dml file will run the  ResidencyMatchMain function in builtin functions  in scripts/builtin
+R = read($1)
+H = read($2)
+C = read($3)
+alg = $4
+if( alg == "residencymatch" )
+[Out] = residencyMatchMain(R=R,H=H,C=C)

Review comment:
       done

##########
File path: src/test/scripts/functions/builtin/residencymatch.dml
##########
@@ -0,0 +1,10 @@
+# this dml file will run the  ResidencyMatchMain function in builtin functions  in scripts/builtin
+R = read($1)
+H = read($2)
+C = read($3)
+alg = $4
+if( alg == "residencymatch" )

Review comment:
       done

##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)
+Capacityrows = nrow(C)
+#######################################################################################################
+Capacity = matrix(0.0, rows=Capacityrows , cols=1)
+Capacity = C;
+max_position = colMaxs(Capacity)
+#######################################################################################################
+# we can consider number of choices for every resident #
+#######################################################################################################
+ResidencyMatch = matrix(0.0, rows=m, cols=n)
+HospitalMatch = matrix(0.0, rows=n, cols=m)
+Result_matrix = matrix(0.0, rows=nrow(R), cols=ncol(R))
+########################################################################################################
+if(nrow(Capacity) != nrow(H)) {
+  print("ERROR: Wrong Input !Capacity indexes is not match with the Number of hospitals ")
+  #it means that some hospitals' capacity is not defined.
+}# end of if
+
+StarM = matrix(1.0, rows=m, cols=1)  ### for checking while
+
+HIndex =matrix(1.0, rows=m, cols=1)
+proposer_pointers = matrix(1.0, rows=m, cols=1)
+prev_Residents_vector = matrix(1.0, rows=n, cols=1)
+prevIndex_Residents_vector = matrix(1.0, rows=n, cols=1)
+
+prev_Residents_vector = rowMins(HospitalMatch)
+prevIndex_Residents_vector =  rowIndexMin(HospitalMatch)
+
+while(sum(StarM) > 0) {
+
+  for(i in 1:m) {
+
+    while (as.scalar (StarM[i]) == 1)  {
+      SecondIndex = as.scalar (proposer_pointers[i])
+      HIndex[i] = as.scalar (R[i,SecondIndex])
+      prev_Residents_vector = rowMaxs(HospitalMatch) # we consider if the preference value is 1 it means it is the first selection of that hospital, the minimum value means most preference.

Review comment:
       done

##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)
+Capacityrows = nrow(C)
+#######################################################################################################

Review comment:
       done

##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)
+Capacityrows = nrow(C)
+#######################################################################################################
+Capacity = matrix(0.0, rows=Capacityrows , cols=1)
+Capacity = C;
+max_position = colMaxs(Capacity)
+#######################################################################################################
+# we can consider number of choices for every resident #
+#######################################################################################################
+ResidencyMatch = matrix(0.0, rows=m, cols=n)
+HospitalMatch = matrix(0.0, rows=n, cols=m)
+Result_matrix = matrix(0.0, rows=nrow(R), cols=ncol(R))
+########################################################################################################
+if(nrow(Capacity) != nrow(H)) {
+  print("ERROR: Wrong Input !Capacity indexes is not match with the Number of hospitals ")
+  #it means that some hospitals' capacity is not defined.
+}# end of if
+
+StarM = matrix(1.0, rows=m, cols=1)  ### for checking while
+
+HIndex =matrix(1.0, rows=m, cols=1)
+proposer_pointers = matrix(1.0, rows=m, cols=1)
+prev_Residents_vector = matrix(1.0, rows=n, cols=1)
+prevIndex_Residents_vector = matrix(1.0, rows=n, cols=1)
+
+prev_Residents_vector = rowMins(HospitalMatch)
+prevIndex_Residents_vector =  rowIndexMin(HospitalMatch)
+
+while(sum(StarM) > 0) {
+
+  for(i in 1:m) {
+
+    while (as.scalar (StarM[i]) == 1)  {
+      SecondIndex = as.scalar (proposer_pointers[i])
+      HIndex[i] = as.scalar (R[i,SecondIndex])
+      prev_Residents_vector = rowMaxs(HospitalMatch) # we consider if the preference value is 1 it means it is the first selection of that hospital, the minimum value means most preference.
+      prevIndex_Residents_vector =  rowIndexMax(HospitalMatch)
+      if (as.scalar(HIndex[i]) != 0 ){
+
+        HosValue = as.scalar (H[as.scalar (HIndex[i]),i])

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648261772



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)
+Capacityrows = nrow(C)
+#######################################################################################################
+Capacity = matrix(0.0, rows=Capacityrows , cols=1)
+Capacity = C;
+max_position = colMaxs(Capacity)
+#######################################################################################################
+# we can consider number of choices for every resident #
+#######################################################################################################
+ResidencyMatch = matrix(0.0, rows=m, cols=n)
+HospitalMatch = matrix(0.0, rows=n, cols=m)
+Result_matrix = matrix(0.0, rows=nrow(R), cols=ncol(R))
+########################################################################################################
+if(nrow(Capacity) != nrow(H)) {
+  print("ERROR: Wrong Input !Capacity indexes is not match with the Number of hospitals ")
+  #it means that some hospitals' capacity is not defined.
+}# end of if
+
+StarM = matrix(1.0, rows=m, cols=1)  ### for checking while
+
+HIndex =matrix(1.0, rows=m, cols=1)
+proposer_pointers = matrix(1.0, rows=m, cols=1)
+prev_Residents_vector = matrix(1.0, rows=n, cols=1)
+prevIndex_Residents_vector = matrix(1.0, rows=n, cols=1)
+
+prev_Residents_vector = rowMins(HospitalMatch)
+prevIndex_Residents_vector =  rowIndexMin(HospitalMatch)
+
+while(sum(StarM) > 0) {
+
+  for(i in 1:m) {
+
+    while (as.scalar (StarM[i]) == 1)  {
+      SecondIndex = as.scalar (proposer_pointers[i])
+      HIndex[i] = as.scalar (R[i,SecondIndex])
+      prev_Residents_vector = rowMaxs(HospitalMatch) # we consider if the preference value is 1 it means it is the first selection of that hospital, the minimum value means most preference.
+      prevIndex_Residents_vector =  rowIndexMax(HospitalMatch)
+      if (as.scalar(HIndex[i]) != 0 ){
+
+        HosValue = as.scalar (H[as.scalar (HIndex[i]),i])

Review comment:
       remove unnecessary space after as.scalar 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648271851



##########
File path: src/test/scripts/functions/builtin/residencymatch.dml
##########
@@ -0,0 +1,10 @@
+# this dml file will run the  ResidencyMatchMain function in builtin functions  in scripts/builtin
+R = read($1)
+H = read($2)
+C = read($3)
+alg = $4
+if( alg == "residencymatch" )
+[Out] = residencyMatchMain(R=R,H=H,C=C)

Review comment:
       please remove the square brackets as the function only return a single output, not a list.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648258529



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")

Review comment:
       in DML we follow two-space indentation. Please indent the code inside the function body.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648260472



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)
+Capacityrows = nrow(C)

Review comment:
       just to follow the consistent naming conventions please start the variable name with a lower-case.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] atefeh-asayesh commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
atefeh-asayesh commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648576792



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] atefeh-asayesh commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
atefeh-asayesh commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648576529



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)
+Capacityrows = nrow(C)

Review comment:
       done




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r648266461



##########
File path: scripts/builtin/residencyMatchMain.dml
##########
@@ -0,0 +1,194 @@
+#-------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+##-------------------------------------------------------------
+# THIS SCRIPT COMPUTES A SOLUTION FOR THE HOSPITAL RESIDENCY MATCH PROBLEM
+#
+# INPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# R                     Matrix     ---          Residents matrix R.
+#                                               It must be an ORDERED  matrix.
+#
+# H                     Matrix     ---          Hospitals matrix H.
+#                                               It must be an UnORDERED matrix.
+#
+# C                     Matrix     ---          Capacity of Hospitals matrix C.
+#                                               It must be a [c,1] matrix with non zero values.
+#                                               i.e. the leftmost value in a row is the most preferred partner's index.
+#                                               i.e. the leftmost value in a row in P is the preference value for the acceptor with index 1 and vice-versa (higher is better).
+# OUTPUT PARAMETERS:
+# --------------------------------------------------------------------------------------------
+# NAME                  TYPE       DEFAULT      MEANING
+# --------------------------------------------------------------------------------------------
+# ResidencyMatch        Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# HospitalMatch         Matrix     ---          Result Matrix
+#                                               If cell [i,j] is non-zero, it means that Resident i has matched with Hospital j.
+#                                               Further, if cell [i,j] is non-zero, it holds the preference value that led to the match.
+#
+#
+# Residents.mtx:
+# 2.0,1.0,3.0
+# 1.0,2.0,3.0
+# 1.0,2.0,0.0
+#
+# Since it is an ORDERED  matrix, this means that Resident 1 (row 1) likes acceptor 2 the most, followed by acceptor 1 and acceptor 3.
+# If it was UNORDERED, this would mean that proposer 1 (row 1) likes acceptor 3 the most (since the value at [1,3] is the row max),
+# followed by acceptor 1 (2.0 preference value) and acceptor 2 (1.0 preference value).
+#
+# Hospitals.mtx:
+# 2.0,1.0,0.0
+# 0.0,1.0,2.0
+# 1.0,2.0,0.0
+#
+# Since it is an UNORDERED matrix this means that Hospital 1 (row 1) likes Resident 1 the most (since the value at [1,1] is the row max).
+#
+# Capacity.mtx
+# 1.0
+# 1.0
+# 1.0
+#
+# ResidencyMatch.mtx
+# 0.0,0.0,3.0
+# 1.0,0.0,0.0
+# 0.0,2.0,0.0
+#
+# HospitalMatch.mtx
+# 0.0,1.0,0.0
+# 0.0,0.0,2.0
+# 1.0,0.0,0.0
+#
+# Resident 1 has matched with Hospital 3 (since [1,3] is non-zero) at a preference level of 3.0.
+# Resident 2 has matched with Hospital 1 (since [2,1] is non-zero) at a preference level of 1.0.
+# Resident 3 has matched with Hospital 2 (since [3,2] is non-zero) at a preference level of 2.0.
+# --------------------------------------------------------------------------------------------
+m_residencyMatchMain = function(Matrix[Double] R, Matrix[Double] H,Matrix[Double] C )
+  return (Matrix[Double] ResidencyMatch)
+{
+#TODO PLEASE PAY ATTENTION
+# in this step we consider that  Residents Matrix is ORDERED   !!!!
+# in this step we consider that  Hospital  Matrix is UNORDERED !!!!
+
+print("STARTING Resident Hospital Match");
+#TODO set a finite number of maximum iterations so that the execution termiates after maximum iterations.
+
+print("\n")
+print("STARTING RESIDENCY MATCH ALGORITHM");
+print("READING R  as residents AND H as Hospitals and also C as capacity...");
+
+m = nrow(R)
+n = ncol (R)
+Capacityrows = nrow(C)
+#######################################################################################################
+Capacity = matrix(0.0, rows=Capacityrows , cols=1)
+Capacity = C;
+max_position = colMaxs(Capacity)
+#######################################################################################################
+# we can consider number of choices for every resident #
+#######################################################################################################
+ResidencyMatch = matrix(0.0, rows=m, cols=n)
+HospitalMatch = matrix(0.0, rows=n, cols=m)
+Result_matrix = matrix(0.0, rows=nrow(R), cols=ncol(R))
+########################################################################################################
+if(nrow(Capacity) != nrow(H)) {
+  print("ERROR: Wrong Input !Capacity indexes is not match with the Number of hospitals ")
+  #it means that some hospitals' capacity is not defined.
+}# end of if
+
+StarM = matrix(1.0, rows=m, cols=1)  ### for checking while
+
+HIndex =matrix(1.0, rows=m, cols=1)
+proposer_pointers = matrix(1.0, rows=m, cols=1)
+prev_Residents_vector = matrix(1.0, rows=n, cols=1)
+prevIndex_Residents_vector = matrix(1.0, rows=n, cols=1)
+
+prev_Residents_vector = rowMins(HospitalMatch)
+prevIndex_Residents_vector =  rowIndexMin(HospitalMatch)
+
+while(sum(StarM) > 0) {
+
+  for(i in 1:m) {
+
+    while (as.scalar (StarM[i]) == 1)  {
+      SecondIndex = as.scalar (proposer_pointers[i])
+      HIndex[i] = as.scalar (R[i,SecondIndex])
+      prev_Residents_vector = rowMaxs(HospitalMatch) # we consider if the preference value is 1 it means it is the first selection of that hospital, the minimum value means most preference.

Review comment:
       Please set a line-width/margin to 80 - 100 characters in your editor to break long lines. 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [systemds] Shafaq-Siddiqi commented on a change in pull request #1306: residency hospital matching

Posted by GitBox <gi...@apache.org>.
Shafaq-Siddiqi commented on a change in pull request #1306:
URL: https://github.com/apache/systemds/pull/1306#discussion_r649027387



##########
File path: src/main/java/org/apache/sysds/common/Builtins.java
##########
@@ -32,31 +31,35 @@
  * always, user-defined DML-bodied functions take precedence over all
  * builtin functions.
  *
- * To add a new builtin script function, simply add the definition here
+ * * To add a new builtin script function, simply add the definition here
  * as well as a dml file in scripts/builtin with a matching name. On
  * building SystemDS, these scripts are packaged into the jar as well.
  */
+
 public enum Builtins {
 	//builtin functions
-	ABSTAIN("abstain", true),

Review comment:
       Do not delete the existing entries from the file.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org